home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume9 / acm / part02 < prev    next >
Encoding:
Internet Message Format  |  1990-10-09  |  65.1 KB

  1. Path: uunet!snorkelwacker!apple!netcom!amdcad!sun!mipsdal.mips.com
  2. From: riley@mipsdal.mips.com (Riley Rainey)
  3. Newsgroups: comp.sources.x
  4. Subject: v09i070: acm, X aerial combat simulation, Part02/05
  5. Message-ID: <143449@sun.Eng.Sun.COM>
  6. Date: 7 Oct 90 18:12:55 GMT
  7. References: <csx-09i069:acm@uunet.UU.NET>
  8. Sender: news@sun.Eng.Sun.COM
  9. Lines: 2395
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: riley@mipsdal.mips.com (Riley Rainey)
  13. Posting-number: Volume 9, Issue 70
  14. Archive-name: acm/part02
  15.  
  16. echo x - ./V/test/f16
  17. sed 's/^X//' >./V/test/f16 <<'*-*-END-of-./V/test/f16-*-*'
  18. XF-16-fighter
  19. X130 12
  20. X1 -18.165 0 0
  21. X2 -18.165 -1.191 0
  22. X3 -15.187 -2.085 0
  23. X4 -13.698 -2.382 0
  24. X5 -17.272 -2.382 0
  25. X6 -17.272 -3.573 0
  26. X7 -10.923 -3.573 0
  27. X8 -4.169 -3.573 0
  28. X9 -4.169 -4.765 0
  29. X10 5.598 -4.765 0
  30. X11 18.463 -2.144 0
  31. X12 18.939 -1.787 0
  32. X13 22.274 -1.489 0
  33. X14 24.895 -1.191 0
  34. X15 27.992 0 0
  35. X16 -6.551 -3.573 0
  36. X17 -6.551 -15.485 0
  37. X18 0.357 -15.485 0
  38. X19 0.357 -15.187 0
  39. X20 -2.978 -15.008 0
  40. X21 5.598 -4.765 0
  41. X22 -4.169 -4.765 0
  42. X23 -4.169 -3.573 0
  43. X24 -17.272 -3.573 0
  44. X25 -17.272 -8.934 0.893
  45. X26 -15.187 -8.934 0.893
  46. X27 -10.923 -3.573 0
  47. X28 27.992 0 0
  48. X29 24.895 1.191 0
  49. X30 22.274 1.489 0
  50. X31 18.939 1.787 0
  51. X32 18.463 2.144 0
  52. X33 5.598 4.765 0
  53. X34 -4.169 4.765 0
  54. X35 -4.169 3.573 0
  55. X36 -10.923 3.573 0
  56. X37 -17.272 3.573 0
  57. X38 -17.272 2.382 0
  58. X39 -13.698 2.382 0
  59. X40 -15.187 2.085 0
  60. X41 -18.165 1.191 0
  61. X42 -18.165 0 0
  62. X43 5.598 4.765 0
  63. X44 -2.978 15.008 0
  64. X45 0.357 15.187 0
  65. X46 0.357 15.485 0
  66. X47 -6.551 15.485 0
  67. X48 -6.551 3.573 0
  68. X49 -4.169 3.573 0
  69. X50 -4.169 4.765 0
  70. X51 -10.923 3.573 0
  71. X52 -15.187 8.934 0.893
  72. X53 -17.272 8.934 0.893
  73. X54 -17.272 3.573 0
  74. X55 27.992 0 0
  75. X56 23.525 0 -1.191
  76. X57 17.272 0 -2.382
  77. X58 15.783 0 -3.812
  78. X59 13.996 0 -4.169
  79. X60 11.316 0 -4.05
  80. X61 8.338 0 -3.335
  81. X62 1.787 0 -2.382
  82. X63 -4.169 0 -2.382
  83. X64 -13.936 0 -1.906
  84. X65 -15.128 0 -1.906
  85. X66 -15.187 0 -1.787
  86. X67 -18.165 0 -1.191
  87. X68 -18.165 0 0
  88. X69 -4.169 0 -2.382
  89. X70 -10.125 0 -4.05
  90. X71 -15.783 0 -10.482
  91. X72 -19.654 0 -10.482
  92. X73 -19.654 0 -9.529
  93. X74 -19.654 0 -9.529
  94. X75 -16.378 0 -3.573
  95. X76 -16.378 0 -2.144
  96. X77 -14.889 0 -2.382
  97. X78 -13.936 0 -2.382
  98. X79 -13.936 0 -1.906
  99. X80 -18.165 0 0
  100. X81 -18.165 0 1.191
  101. X82 -15.187 0 2.085
  102. X83 -13.698 0 2.263
  103. X84 -2.68 0 2.382
  104. X85 8.04 0 2.382
  105. X86 12.507 0 2.263
  106. X87 12.507 0 0.596
  107. X88 19.952 0 0.596
  108. X89 23.525 0 0.476
  109. X90 27.992 0 0
  110. X91 -3.551 0 -2.382
  111. X92 -3.551 -3.871 -0.10
  112. X93 -3.551 -15.485 0
  113. X94 -3.551 -15.485 0.1065
  114. X95 -3.551 -3.871 0.142
  115. X96 -3.551 -2.58 0.2556
  116. X97 -3.551 -2.387 1.818
  117. X98 -3.551 -2.102 2.015
  118. X99 -3.551 -1.03 2.251
  119. X100 -3.551 0 2.282
  120. X101 -3.551 1.03 2.251
  121. X102 -3.551 2.102 2.015
  122. X103 -3.551 2.387 1.818
  123. X104 -3.551 2.58 0.2556
  124. X105 -3.551 3.871 0.142
  125. X106 -3.551 15.485 0.1065
  126. X107 -3.551 15.485 0
  127. X108 -3.551 3.871 -0.10
  128. X109 13.996 0 -4.169
  129. X110 13.996 -0.8932 -3.692
  130. X111 13.996 -1.191 -2.978
  131. X112 13.996 -1.251 -2.502
  132. X113 13.996 -1.787 -1.311
  133. X114 13.996 -3.054 0
  134. X115 13.996 -1.583 0.3568
  135. X116 13.996 0 0.596
  136. X117 13.996 1.583 0.3568
  137. X118 13.996 3.054 0
  138. X119 13.996 1.787 -1.311
  139. X120 13.996 1.251 -2.502
  140. X121 13.996 1.191 -2.978
  141. X122 13.996 0.8932 -3.692
  142. X123 -18.165 1.191 0
  143. X124 -18.165 0.842 0.842
  144. X125 -18.165 0 1.191
  145. X126 -18.165 -0.842 0.842
  146. X127 -18.165 -1.191 0
  147. X128 -18.165 -0.842 -0.842
  148. X129 -18.165 0 -1.191
  149. X130 -18.165 0.842 -0.842
  150. Xgray33 14 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  151. Xgray33 18 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  152. Xgray33 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  153. Xgray33 8 16 17 18 19 20 21 22 23
  154. Xgray33 4 24 25 26 27
  155. Xgray33 15 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  156. Xgray33 8 43 44 45 46 47 48 49 50
  157. Xgray33 4 51 52 53 54
  158. Xgray33 14 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  159. Xgray33 11 69 70 71 72 73 74 75 76 77 78 79
  160. Xgray33 11 80 81 82 83 84 85 86 87 88 89 90
  161. Xgray33 8 123 124 125 126 127 128 129 130
  162. *-*-END-of-./V/test/f16-*-*
  163. echo x - ./V/test/Makefile
  164. sed 's/^X//' >./V/test/Makefile <<'*-*-END-of-./V/test/Makefile-*-*'
  165. X#  Makefile for V library test programs
  166. X#
  167. X#  Riley Rainey; riley@10hnl1.ceo.dg.com
  168. X#
  169. X#  This makefile can be used to create a demonstration program
  170. X#  for the V library.  This program, named animate,  uses the V library
  171. X#  and X color palette manipulation to create an animated flying scene.
  172. XOBJFILES = animate.o app.o
  173. XCFLAGS = -g
  174. X
  175. Xanimate: $(OBJFILES)
  176. X    cc -g -o animate $(OBJFILES) -L/usr/lib/X11 -L../lib -lV -lX11 -lm -lbsd
  177. X
  178. Xclean:
  179. X    rm *.o core
  180. X
  181. Xclobber:
  182. X    rm *.o animate
  183. *-*-END-of-./V/test/Makefile-*-*
  184. echo x - ./V/test/fixf16.c
  185. sed 's/^X//' >./V/test/fixf16.c <<'*-*-END-of-./V/test/fixf16.c-*-*'
  186. X#include "../lib/Vlib.h"
  187. X
  188. Xmain () {
  189. X
  190. X    int    i, k;
  191. X    VObject *obj;
  192. X    VPolygon **poly;
  193. X    VPoint    *q, tmp;
  194. X    VMatrix mtx;
  195. X
  196. X        if ((obj = VReadObject(stdin)) == (VObject *) NULL) {
  197. X                fprintf (stderr, "Error reading the object definition.\n");
  198. X                exit (1);
  199. X        }
  200. X
  201. X/*
  202. X *  Prepare a transformation matrix that:
  203. X *    (a) swaps X and Y coordinates.
  204. X *    (b) negates Z coordinate.
  205. X */
  206. X
  207. X    VIdentMatrix (&mtx);
  208. X    mtx.m[0][0] = 0.0;
  209. X    mtx.m[0][1] = 1.0;
  210. X    mtx.m[1][0] = 1.0;
  211. X    mtx.m[1][1] = 0.0;
  212. X    mtx.m[2][2] = -1.0;
  213. X
  214. X    poly = obj->polygon;
  215. X
  216. X        for (i=0; i<obj->numPolys; ++i) {
  217. X            for ((k=0, q=poly[i]->vertex); k<poly[i]->numVtces; (++k, ++q)) {
  218. X                    VTransform(q, &mtx, &tmp);
  219. X                    *q = tmp;
  220. X            }
  221. X        }
  222. X
  223. X    VWriteObject (stdout, obj);
  224. X}
  225. *-*-END-of-./V/test/fixf16.c-*-*
  226. echo x - ./V/test/f
  227. sed 's/^X//' >./V/test/f <<'*-*-END-of-./V/test/f-*-*'
  228. XF-16-fighter
  229. X90 9
  230. X1 -18.165 0 0
  231. X2 -18.165 -1.191 0
  232. X3 -15.187 -2.085 0
  233. X4 -13.698 -2.382 0
  234. X5 -17.272 -2.382 0
  235. X6 -17.272 -3.573 0
  236. X7 -10.923 -3.573 0
  237. X8 -4.169 -3.573 0
  238. X9 -4.169 -4.765 0
  239. X10 5.598 -4.765 0
  240. X11 18.463 -2.144 0
  241. X12 18.939 -1.787 0
  242. X13 22.274 -1.489 0
  243. X14 24.895 -1.191 0
  244. X15 27.992 0 0
  245. X16 -6.551 -3.573 0
  246. X17 -6.551 -15.485 0
  247. X18 0.357 -15.485 0
  248. X19 0.357 -15.187 0
  249. X20 -2.978 -15.008 0
  250. X21 5.598 -4.765 0
  251. X22 -4.169 -4.765 0
  252. X23 -4.169 -3.573 0
  253. X24 -17.272 -3.573 0
  254. X25 -17.272 -8.934 0.893
  255. X26 -15.187 -8.934 0.893
  256. X27 -10.923 -3.573 0
  257. X28 27.992 0 0
  258. X29 24.895 1.191 0
  259. X30 22.274 1.489 0
  260. X31 18.939 1.787 0
  261. X32 18.463 2.144 0
  262. X33 5.598 4.765 0
  263. X34 -4.169 4.765 0
  264. X35 -4.169 3.573 0
  265. X36 -10.923 3.573 0
  266. X37 -17.272 3.573 0
  267. X38 -17.272 2.382 0
  268. X39 -13.698 2.382 0
  269. X40 -15.187 2.085 0
  270. X41 -18.165 1.191 0
  271. X42 -18.165 0 0
  272. X43 5.598 4.765 0
  273. X44 -2.978 15.008 0
  274. X45 0.357 15.187 0
  275. X46 0.357 15.485 0
  276. X47 -6.551 15.485 0
  277. X48 -6.551 3.573 0
  278. X49 -4.169 3.573 0
  279. X50 -4.169 4.765 0
  280. X51 -10.923 3.573 0
  281. X52 -15.187 8.934 0.893
  282. X53 -17.272 8.934 0.893
  283. X54 -17.272 3.573 0
  284. X55 27.992 0 0
  285. X56 23.525 0 -1.191
  286. X57 17.272 0 -2.382
  287. X58 15.783 0 -3.812
  288. X59 13.996 0 -4.169
  289. X60 11.316 0 -4.05
  290. X61 8.338 0 -3.335
  291. X62 1.787 0 -2.382
  292. X63 -4.169 0 -2.382
  293. X64 -13.936 0 -1.906
  294. X65 -15.128 0 -1.906
  295. X66 -15.187 0 -1.787
  296. X67 -18.165 0 -1.191
  297. X68 -18.165 0 0
  298. X69 -4.169 0 -2.382
  299. X70 -10.125 0 -4.05
  300. X71 -15.783 0 -10.482
  301. X72 -19.654 0 -10.482
  302. X73 -19.654 0 -9.529
  303. X74 -19.654 0 -9.529
  304. X75 -16.378 0 -3.573
  305. X76 -16.378 0 -2.144
  306. X77 -14.889 0 -2.382
  307. X78 -13.936 0 -2.382
  308. X79 -13.936 0 -1.906
  309. X80 -18.165 0 0
  310. X81 -18.165 0 1.191
  311. X82 -15.187 0 2.085
  312. X83 -13.698 0 2.263
  313. X84 -2.68 0 2.382
  314. X85 8.04 0 2.382
  315. X86 12.507 0 2.263
  316. X87 12.507 0 0.596
  317. X88 19.952 0 0.596
  318. X89 23.525 0 0.476
  319. X90 27.992 0 0
  320. Xgray 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  321. Xgray 8 16 17 18 19 20 21 22 23
  322. Xgray 4 24 25 26 27
  323. Xgray 15 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  324. Xgray 8 43 44 45 46 47 48 49 50
  325. Xgray 4 51 52 53 54
  326. Xgray 14 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  327. Xgray 11 69 70 71 72 73 74 75 76 77 78 79
  328. Xgray 11 80 81 82 83 84 85 86 87 88 89 90
  329. *-*-END-of-./V/test/f-*-*
  330. echo x - ./V/test/mig23
  331. sed 's/^X//' >./V/test/mig23 <<'*-*-END-of-./V/test/mig23-*-*'
  332. Xmig-23-wings-swept
  333. X88 10
  334. X1 36.5891 0 0
  335. X2 34.4368 0.86092 0
  336. X3 30.9931 1.29138 0
  337. X4 27.119 1.72184 0
  338. X5 20.6621 1.72184 0
  339. X6 18.9402 2.1523 0
  340. X7 14.2052 3.01322 0
  341. X8 -3.44368 2.58276 0
  342. X9 -9.03966 2.1523 0
  343. X10 -16.7879 0.86092 0
  344. X11 -18.0793 0.43046 0
  345. X12 -18.0793 0 0
  346. X13 36.5891 0 0
  347. X14 34.4368 -0.86092 0
  348. X15 30.9931 -1.29138 0
  349. X16 27.119 -1.72184 0
  350. X17 20.6621 -1.72184 0
  351. X18 18.9402 -2.1523 0
  352. X19 14.2052 -3.01322 0
  353. X20 -3.44368 -2.58276 0
  354. X21 -9.03966 -2.1523 0
  355. X22 -16.7879 -0.86092 0
  356. X23 -18.0793 -0.43046 0
  357. X24 -18.0793 0 0
  358. X25 14.2052 3.01322 -3.01322
  359. X26 4.73506 7.31782 -3.01322
  360. X27 6.02644 8.6092 -3.01322
  361. X28 -11.192 13.7747 -3.01322
  362. X29 -12.0529 13.7747 -3.01322
  363. X30 -14.2052 11.192 -3.01322
  364. X31 -14.2052 10.7615 -3.01322
  365. X32 -3.44368 2.58276 -3.01322
  366. X33 14.2052 -3.01322 -3.01322
  367. X34 4.73506 -7.31782 -3.01322
  368. X35 6.02644 -8.6092 -3.01322
  369. X36 -11.192 -13.7747 -3.01322
  370. X37 -12.0529 -13.7747 -3.01322
  371. X38 -14.2052 -11.192 -3.01322
  372. X39 -14.2052 -10.7615 -3.01322
  373. X40 -3.44368 -2.58276 -3.01322
  374. X41 -18.9402 3.01322 -1.72184
  375. X42 -20.2316 7.31782 -1.72184
  376. X43 -18.5098 8.6092 -1.72184
  377. X44 -9.03966 2.1523 -1.72184
  378. X45 -16.7879 0.86092 -1.72184
  379. X46 -18.9402 -3.01322 -1.72184
  380. X47 -20.2316 -7.31782 -1.72184
  381. X48 -18.5098 -8.6092 -1.72184
  382. X49 -9.03966 -2.1523 -1.72184
  383. X50 -16.7879 -0.86092 -1.72184
  384. X51 36.5891 0 0
  385. X52 33.1454 0 -1.29138
  386. X53 30.1322 0 -2.1523
  387. X54 25.8276 0 -2.58276
  388. X55 22.3839 0 -3.87414
  389. X56 18.0793 0 -4.3046
  390. X57 9.47012 0 -3.87414
  391. X58 -0.860918 0 -3.44368
  392. X59 -8.6092 0 -6.02644
  393. X60 -16.3575 0 -10.331
  394. X61 -18.9402 0 -9.03966
  395. X62 -18.0793 0 -3.87414
  396. X63 -19.8012 0 -3.44368
  397. X64 -17.2184 0 -1.72184
  398. X65 -18.0793 0 -1.72184
  399. X66 -18.0793 0 1.29138
  400. X67 -15.4966 0 1.72184
  401. X68 -6.4569 0 2.1523
  402. X69 10.331 0 2.1523
  403. X70 20.2316 0 1.72184
  404. X71 28.8408 0 1.29138
  405. X72 33.1454 0 0.86092
  406. X73 -15.4966 0 1.72184
  407. X74 -15.4966 0 4.3046
  408. X75 -13.3443 0 5.16552
  409. X76 -6.4569 0 2.1523
  410. X77 20.6621 1.72184 -3.01322
  411. X78 18.9402 2.1523 -3.01322
  412. X79 14.2052 3.01322 -3.01322
  413. X80 -3.44368 2.58276 -3.01322
  414. X81 -3.44368 -2.58276 -3.01322
  415. X82 14.2052 -3.01322 -3.01322
  416. X83 18.9402 -2.1523 -3.01322
  417. X84 20.6621 -1.72184 -3.01322
  418. X85 -3.44368 2.58276 -3.01322
  419. X86 -16.7879 0.86092 -1.72184
  420. X87 -16.7879 -0.86092 -1.72184
  421. X88 -3.44368 -2.58276 -3.01322
  422. Xgray 12 1 2 3 4 5 6 7 8 9 10 11 12
  423. Xgray 12 13 14 15 16 17 18 19 20 21 22 23 24
  424. Xgray 8 25 26 27 28 29 30 31 32
  425. Xgray 8 33 34 35 36 37 38 39 40
  426. Xgray 5 41 42 43 44 45
  427. Xgray 5 46 47 48 49 50
  428. Xgray 22 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  429. Xgray 4 73 74 75 76
  430. Xgray 8 77 78 79 80 81 82 83 84
  431. Xgray 4 85 86 87 88
  432. *-*-END-of-./V/test/mig23-*-*
  433. echo x - ./V/test/fixmig.c
  434. sed 's/^X//' >./V/test/fixmig.c <<'*-*-END-of-./V/test/fixmig.c-*-*'
  435. X#include "../lib/Vlib.h"
  436. X
  437. Xmain () {
  438. X
  439. X    int    i, k;
  440. X    VObject *obj;
  441. X    VPolygon **poly;
  442. X    VPoint    *q, tmp;
  443. X    VMatrix mtx;
  444. X
  445. X        if ((obj = VReadObject(stdin)) == (VObject *) NULL) {
  446. X                fprintf (stderr, "Error reading the object definition.\n");
  447. X                exit (1);
  448. X        }
  449. X
  450. X/*
  451. X *  Prepare a transformation matrix that:
  452. X *    (a) swaps X and Y coordinates.
  453. X *    (b) negates Z coordinate.
  454. X */
  455. X
  456. X    VIdentMatrix (&mtx);
  457. X    mtx.m[0][3] = 39.60232;
  458. X    mtx.m[0][0] = -2.1523;
  459. X    mtx.m[1][1] = 2.1523;
  460. X    mtx.m[2][2] = 2.1523;
  461. X
  462. X    poly = obj->polygon;
  463. X
  464. X        for (i=0; i<obj->numPolys; ++i) {
  465. X            for ((k=0, q=poly[i]->vertex); k<poly[i]->numVtces; (++k, ++q)) {
  466. X                    VTransform(q, &mtx, &tmp);
  467. X                    *q = tmp;
  468. X            }
  469. X        }
  470. X
  471. X    VWriteObject (stdout, obj);
  472. X}
  473. *-*-END-of-./V/test/fixmig.c-*-*
  474. echo x - ./V/test/fullrwy
  475. sed 's/^X//' >./V/test/fullrwy <<'*-*-END-of-./V/test/fullrwy-*-*'
  476. XRunway
  477. X280 69
  478. X1 0.000000 -75.000000 0.000000
  479. X2 12000.000000 -75.000000 0.000000
  480. X3 12000.000000 75.000000 0.000000
  481. X4 0.000000 75.000000 0.000000
  482. X5 0.000000 -75.000000 0.000000
  483. X6 12000.000000 -75.000000 0.000000
  484. X7 12000.000000 -70.000000 0.000000
  485. X8 0.000000 -70.000000 0.000000
  486. X9 0.000000 75.000000 0.000000
  487. X10 12000.000000 75.000000 0.000000
  488. X11 12000.000000 70.000000 0.000000
  489. X12 0.000000 70.000000 0.000000
  490. X13 1000.000000 -66.000000 0.000000
  491. X14 1125.000000 -66.000000 0.000000
  492. X15 1125.000000 -36.000000 0.000000
  493. X16 1000.000000 -36.000000 0.000000
  494. X17 1000.000000 66.000000 0.000000
  495. X18 1125.000000 66.000000 0.000000
  496. X19 1125.000000 36.000000 0.000000
  497. X20 1000.000000 36.000000 0.000000
  498. X21 11000.000000 -66.000000 0.000000
  499. X22 10875.000000 -66.000000 0.000000
  500. X23 10875.000000 -36.000000 0.000000
  501. X24 11000.000000 -36.000000 0.000000
  502. X25 11000.000000 66.000000 0.000000
  503. X26 10875.000000 66.000000 0.000000
  504. X27 10875.000000 36.000000 0.000000
  505. X28 11000.000000 36.000000 0.000000
  506. X29 4.000000 -66.000000 0.000000
  507. X30 129.000000 -66.000000 0.000000
  508. X31 129.000000 -54.888889 0.000000
  509. X32 4.000000 -54.888889 0.000000
  510. X33 4.000000 -50.888889 0.000000
  511. X34 129.000000 -50.888889 0.000000
  512. X35 129.000000 -39.777779 0.000000
  513. X36 4.000000 -39.777779 0.000000
  514. X37 4.000000 -35.777779 0.000000
  515. X38 129.000000 -35.777779 0.000000
  516. X39 129.000000 -24.666666 0.000000
  517. X40 4.000000 -24.666666 0.000000
  518. X41 4.000000 -20.666666 0.000000
  519. X42 129.000000 -20.666666 0.000000
  520. X43 129.000000 -9.555555 0.000000
  521. X44 4.000000 -9.555555 0.000000
  522. X45 4.000000 9.555555 0.000000
  523. X46 129.000000 9.555555 0.000000
  524. X47 129.000000 20.666666 0.000000
  525. X48 4.000000 20.666666 0.000000
  526. X49 4.000000 24.666666 0.000000
  527. X50 129.000000 24.666666 0.000000
  528. X51 129.000000 35.777779 0.000000
  529. X52 4.000000 35.777779 0.000000
  530. X53 4.000000 39.777779 0.000000
  531. X54 129.000000 39.777779 0.000000
  532. X55 129.000000 50.888889 0.000000
  533. X56 4.000000 50.888889 0.000000
  534. X57 4.000000 54.888889 0.000000
  535. X58 129.000000 54.888889 0.000000
  536. X59 129.000000 66.000000 0.000000
  537. X60 4.000000 66.000000 0.000000
  538. X61 11996.000000 -66.000000 0.000000
  539. X62 11871.000000 -66.000000 0.000000
  540. X63 11871.000000 -54.888889 0.000000
  541. X64 11996.000000 -54.888889 0.000000
  542. X65 11996.000000 -50.888889 0.000000
  543. X66 11871.000000 -50.888889 0.000000
  544. X67 11871.000000 -39.777779 0.000000
  545. X68 11996.000000 -39.777779 0.000000
  546. X69 11996.000000 -35.777779 0.000000
  547. X70 11871.000000 -35.777779 0.000000
  548. X71 11871.000000 -24.666666 0.000000
  549. X72 11996.000000 -24.666666 0.000000
  550. X73 11996.000000 -20.666666 0.000000
  551. X74 11871.000000 -20.666666 0.000000
  552. X75 11871.000000 -9.555555 0.000000
  553. X76 11996.000000 -9.555555 0.000000
  554. X77 11996.000000 9.555555 0.000000
  555. X78 11871.000000 9.555555 0.000000
  556. X79 11871.000000 20.666666 0.000000
  557. X80 11996.000000 20.666666 0.000000
  558. X81 11996.000000 24.666666 0.000000
  559. X82 11871.000000 24.666666 0.000000
  560. X83 11871.000000 35.777779 0.000000
  561. X84 11996.000000 35.777779 0.000000
  562. X85 11996.000000 39.777779 0.000000
  563. X86 11871.000000 39.777779 0.000000
  564. X87 11871.000000 50.888889 0.000000
  565. X88 11996.000000 50.888889 0.000000
  566. X89 11996.000000 54.888889 0.000000
  567. X90 11871.000000 54.888889 0.000000
  568. X91 11871.000000 66.000000 0.000000
  569. X92 11996.000000 66.000000 0.000000
  570. X93 258.000000 -2.500000 0.000000
  571. X94 383.000000 -2.500000 0.000000
  572. X95 383.000000 2.500000 0.000000
  573. X96 258.000000 2.500000 0.000000
  574. X97 508.000000 -2.500000 0.000000
  575. X98 633.000000 -2.500000 0.000000
  576. X99 633.000000 2.500000 0.000000
  577. X100 508.000000 2.500000 0.000000
  578. X101 758.000000 -2.500000 0.000000
  579. X102 883.000000 -2.500000 0.000000
  580. X103 883.000000 2.500000 0.000000
  581. X104 758.000000 2.500000 0.000000
  582. X105 1008.000000 -2.500000 0.000000
  583. X106 1133.000000 -2.500000 0.000000
  584. X107 1133.000000 2.500000 0.000000
  585. X108 1008.000000 2.500000 0.000000
  586. X109 1258.000000 -2.500000 0.000000
  587. X110 1383.000000 -2.500000 0.000000
  588. X111 1383.000000 2.500000 0.000000
  589. X112 1258.000000 2.500000 0.000000
  590. X113 1508.000000 -2.500000 0.000000
  591. X114 1633.000000 -2.500000 0.000000
  592. X115 1633.000000 2.500000 0.000000
  593. X116 1508.000000 2.500000 0.000000
  594. X117 1758.000000 -2.500000 0.000000
  595. X118 1883.000000 -2.500000 0.000000
  596. X119 1883.000000 2.500000 0.000000
  597. X120 1758.000000 2.500000 0.000000
  598. X121 2008.000000 -2.500000 0.000000
  599. X122 2133.000000 -2.500000 0.000000
  600. X123 2133.000000 2.500000 0.000000
  601. X124 2008.000000 2.500000 0.000000
  602. X125 2258.000000 -2.500000 0.000000
  603. X126 2383.000000 -2.500000 0.000000
  604. X127 2383.000000 2.500000 0.000000
  605. X128 2258.000000 2.500000 0.000000
  606. X129 2508.000000 -2.500000 0.000000
  607. X130 2633.000000 -2.500000 0.000000
  608. X131 2633.000000 2.500000 0.000000
  609. X132 2508.000000 2.500000 0.000000
  610. X133 2758.000000 -2.500000 0.000000
  611. X134 2883.000000 -2.500000 0.000000
  612. X135 2883.000000 2.500000 0.000000
  613. X136 2758.000000 2.500000 0.000000
  614. X137 3008.000000 -2.500000 0.000000
  615. X138 3133.000000 -2.500000 0.000000
  616. X139 3133.000000 2.500000 0.000000
  617. X140 3008.000000 2.500000 0.000000
  618. X141 3258.000000 -2.500000 0.000000
  619. X142 3383.000000 -2.500000 0.000000
  620. X143 3383.000000 2.500000 0.000000
  621. X144 3258.000000 2.500000 0.000000
  622. X145 3508.000000 -2.500000 0.000000
  623. X146 3633.000000 -2.500000 0.000000
  624. X147 3633.000000 2.500000 0.000000
  625. X148 3508.000000 2.500000 0.000000
  626. X149 3758.000000 -2.500000 0.000000
  627. X150 3883.000000 -2.500000 0.000000
  628. X151 3883.000000 2.500000 0.000000
  629. X152 3758.000000 2.500000 0.000000
  630. X153 4008.000000 -2.500000 0.000000
  631. X154 4133.000000 -2.500000 0.000000
  632. X155 4133.000000 2.500000 0.000000
  633. X156 4008.000000 2.500000 0.000000
  634. X157 4258.000000 -2.500000 0.000000
  635. X158 4383.000000 -2.500000 0.000000
  636. X159 4383.000000 2.500000 0.000000
  637. X160 4258.000000 2.500000 0.000000
  638. X161 4508.000000 -2.500000 0.000000
  639. X162 4633.000000 -2.500000 0.000000
  640. X163 4633.000000 2.500000 0.000000
  641. X164 4508.000000 2.500000 0.000000
  642. X165 4758.000000 -2.500000 0.000000
  643. X166 4883.000000 -2.500000 0.000000
  644. X167 4883.000000 2.500000 0.000000
  645. X168 4758.000000 2.500000 0.000000
  646. X169 5008.000000 -2.500000 0.000000
  647. X170 5133.000000 -2.500000 0.000000
  648. X171 5133.000000 2.500000 0.000000
  649. X172 5008.000000 2.500000 0.000000
  650. X173 5258.000000 -2.500000 0.000000
  651. X174 5383.000000 -2.500000 0.000000
  652. X175 5383.000000 2.500000 0.000000
  653. X176 5258.000000 2.500000 0.000000
  654. X177 5508.000000 -2.500000 0.000000
  655. X178 5633.000000 -2.500000 0.000000
  656. X179 5633.000000 2.500000 0.000000
  657. X180 5508.000000 2.500000 0.000000
  658. X181 5758.000000 -2.500000 0.000000
  659. X182 5883.000000 -2.500000 0.000000
  660. X183 5883.000000 2.500000 0.000000
  661. X184 5758.000000 2.500000 0.000000
  662. X185 6008.000000 -2.500000 0.000000
  663. X186 6133.000000 -2.500000 0.000000
  664. X187 6133.000000 2.500000 0.000000
  665. X188 6008.000000 2.500000 0.000000
  666. X189 6258.000000 -2.500000 0.000000
  667. X190 6383.000000 -2.500000 0.000000
  668. X191 6383.000000 2.500000 0.000000
  669. X192 6258.000000 2.500000 0.000000
  670. X193 6508.000000 -2.500000 0.000000
  671. X194 6633.000000 -2.500000 0.000000
  672. X195 6633.000000 2.500000 0.000000
  673. X196 6508.000000 2.500000 0.000000
  674. X197 6758.000000 -2.500000 0.000000
  675. X198 6883.000000 -2.500000 0.000000
  676. X199 6883.000000 2.500000 0.000000
  677. X200 6758.000000 2.500000 0.000000
  678. X201 7008.000000 -2.500000 0.000000
  679. X202 7133.000000 -2.500000 0.000000
  680. X203 7133.000000 2.500000 0.000000
  681. X204 7008.000000 2.500000 0.000000
  682. X205 7258.000000 -2.500000 0.000000
  683. X206 7383.000000 -2.500000 0.000000
  684. X207 7383.000000 2.500000 0.000000
  685. X208 7258.000000 2.500000 0.000000
  686. X209 7508.000000 -2.500000 0.000000
  687. X210 7633.000000 -2.500000 0.000000
  688. X211 7633.000000 2.500000 0.000000
  689. X212 7508.000000 2.500000 0.000000
  690. X213 7758.000000 -2.500000 0.000000
  691. X214 7883.000000 -2.500000 0.000000
  692. X215 7883.000000 2.500000 0.000000
  693. X216 7758.000000 2.500000 0.000000
  694. X217 8008.000000 -2.500000 0.000000
  695. X218 8133.000000 -2.500000 0.000000
  696. X219 8133.000000 2.500000 0.000000
  697. X220 8008.000000 2.500000 0.000000
  698. X221 8258.000000 -2.500000 0.000000
  699. X222 8383.000000 -2.500000 0.000000
  700. X223 8383.000000 2.500000 0.000000
  701. X224 8258.000000 2.500000 0.000000
  702. X225 8508.000000 -2.500000 0.000000
  703. X226 8633.000000 -2.500000 0.000000
  704. X227 8633.000000 2.500000 0.000000
  705. X228 8508.000000 2.500000 0.000000
  706. X229 8758.000000 -2.500000 0.000000
  707. X230 8883.000000 -2.500000 0.000000
  708. X231 8883.000000 2.500000 0.000000
  709. X232 8758.000000 2.500000 0.000000
  710. X233 9008.000000 -2.500000 0.000000
  711. X234 9133.000000 -2.500000 0.000000
  712. X235 9133.000000 2.500000 0.000000
  713. X236 9008.000000 2.500000 0.000000
  714. X237 9258.000000 -2.500000 0.000000
  715. X238 9383.000000 -2.500000 0.000000
  716. X239 9383.000000 2.500000 0.000000
  717. X240 9258.000000 2.500000 0.000000
  718. X241 9508.000000 -2.500000 0.000000
  719. X242 9633.000000 -2.500000 0.000000
  720. X243 9633.000000 2.500000 0.000000
  721. X244 9508.000000 2.500000 0.000000
  722. X245 9758.000000 -2.500000 0.000000
  723. X246 9883.000000 -2.500000 0.000000
  724. X247 9883.000000 2.500000 0.000000
  725. X248 9758.000000 2.500000 0.000000
  726. X249 10008.000000 -2.500000 0.000000
  727. X250 10133.000000 -2.500000 0.000000
  728. X251 10133.000000 2.500000 0.000000
  729. X252 10008.000000 2.500000 0.000000
  730. X253 10258.000000 -2.500000 0.000000
  731. X254 10383.000000 -2.500000 0.000000
  732. X255 10383.000000 2.500000 0.000000
  733. X256 10258.000000 2.500000 0.000000
  734. X257 10508.000000 -2.500000 0.000000
  735. X258 10633.000000 -2.500000 0.000000
  736. X259 10633.000000 2.500000 0.000000
  737. X260 10508.000000 2.500000 0.000000
  738. X261 10758.000000 -2.500000 0.000000
  739. X262 10883.000000 -2.500000 0.000000
  740. X263 10883.000000 2.500000 0.000000
  741. X264 10758.000000 2.500000 0.000000
  742. X265 11008.000000 -2.500000 0.000000
  743. X266 11133.000000 -2.500000 0.000000
  744. X267 11133.000000 2.500000 0.000000
  745. X268 11008.000000 2.500000 0.000000
  746. X269 11258.000000 -2.500000 0.000000
  747. X270 11383.000000 -2.500000 0.000000
  748. X271 11383.000000 2.500000 0.000000
  749. X272 11258.000000 2.500000 0.000000
  750. X273 11508.000000 -2.500000 0.000000
  751. X274 11633.000000 -2.500000 0.000000
  752. X275 11633.000000 2.500000 0.000000
  753. X276 11508.000000 2.500000 0.000000
  754. X277 11758.000000 -2.500000 0.000000
  755. X278 11883.000000 -2.500000 0.000000
  756. X279 11883.000000 2.500000 0.000000
  757. X280 11758.000000 2.500000 0.000000
  758. Xblack 4  1 2 3 4
  759. Xwhite 4  5 6 7 8
  760. Xwhite 4  9 10 11 12
  761. Xwhite 4  13 14 15 16
  762. Xwhite 4  17 18 19 20
  763. Xwhite 4  21 22 23 24
  764. Xwhite 4  25 26 27 28
  765. Xwhite 4  29 30 31 32
  766. Xwhite 4  33 34 35 36
  767. Xwhite 4  37 38 39 40
  768. Xwhite 4  41 42 43 44
  769. Xwhite 4  45 46 47 48
  770. Xwhite 4  49 50 51 52
  771. Xwhite 4  53 54 55 56
  772. Xwhite 4  57 58 59 60
  773. Xwhite 4  61 62 63 64
  774. Xwhite 4  65 66 67 68
  775. Xwhite 4  69 70 71 72
  776. Xwhite 4  73 74 75 76
  777. Xwhite 4  77 78 79 80
  778. Xwhite 4  81 82 83 84
  779. Xwhite 4  85 86 87 88
  780. Xwhite 4  89 90 91 92
  781. Xwhite 4  93 94 95 96
  782. Xwhite 4  97 98 99 100
  783. Xwhite 4  101 102 103 104
  784. Xwhite 4  105 106 107 108
  785. Xwhite 4  109 110 111 112
  786. Xwhite 4  113 114 115 116
  787. Xwhite 4  117 118 119 120
  788. Xwhite 4  121 122 123 124
  789. Xwhite 4  125 126 127 128
  790. Xwhite 4  129 130 131 132
  791. Xwhite 4  133 134 135 136
  792. Xwhite 4  137 138 139 140
  793. Xwhite 4  141 142 143 144
  794. Xwhite 4  145 146 147 148
  795. Xwhite 4  149 150 151 152
  796. Xwhite 4  153 154 155 156
  797. Xwhite 4  157 158 159 160
  798. Xwhite 4  161 162 163 164
  799. Xwhite 4  165 166 167 168
  800. Xwhite 4  169 170 171 172
  801. Xwhite 4  173 174 175 176
  802. Xwhite 4  177 178 179 180
  803. Xwhite 4  181 182 183 184
  804. Xwhite 4  185 186 187 188
  805. Xwhite 4  189 190 191 192
  806. Xwhite 4  193 194 195 196
  807. Xwhite 4  197 198 199 200
  808. Xwhite 4  201 202 203 204
  809. Xwhite 4  205 206 207 208
  810. Xwhite 4  209 210 211 212
  811. Xwhite 4  213 214 215 216
  812. Xwhite 4  217 218 219 220
  813. Xwhite 4  221 222 223 224
  814. Xwhite 4  225 226 227 228
  815. Xwhite 4  229 230 231 232
  816. Xwhite 4  233 234 235 236
  817. Xwhite 4  237 238 239 240
  818. Xwhite 4  241 242 243 244
  819. Xwhite 4  245 246 247 248
  820. Xwhite 4  249 250 251 252
  821. Xwhite 4  253 254 255 256
  822. Xwhite 4  257 258 259 260
  823. Xwhite 4  261 262 263 264
  824. Xwhite 4  265 266 267 268
  825. Xwhite 4  269 270 271 272
  826. Xwhite 4  273 274 275 276
  827. Xwhite 4  277 278 279 280
  828. *-*-END-of-./V/test/fullrwy-*-*
  829. echo x - ./V/test/hold
  830. sed 's/^X//' >./V/test/hold <<'*-*-END-of-./V/test/hold-*-*'
  831. XF-16-fighter
  832. X122 11
  833. X1 -18.165 0 0
  834. X2 -18.165 -1.191 0
  835. X3 -15.187 -2.085 0
  836. X4 -13.698 -2.382 0
  837. X5 -17.272 -2.382 0
  838. X6 -17.272 -3.573 0
  839. X7 -10.923 -3.573 0
  840. X8 -4.169 -3.573 0
  841. X9 -4.169 -4.765 0
  842. X10 5.598 -4.765 0
  843. X11 18.463 -2.144 0
  844. X12 18.939 -1.787 0
  845. X13 22.274 -1.489 0
  846. X14 24.895 -1.191 0
  847. X15 27.992 0 0
  848. X16 -6.551 -3.573 0
  849. X17 -6.551 -15.485 0
  850. X18 0.357 -15.485 0
  851. X19 0.357 -15.187 0
  852. X20 -2.978 -15.008 0
  853. X21 5.598 -4.765 0
  854. X22 -4.169 -4.765 0
  855. X23 -4.169 -3.573 0
  856. X24 -17.272 -3.573 0
  857. X25 -17.272 -8.934 0.893
  858. X26 -15.187 -8.934 0.893
  859. X27 -10.923 -3.573 0
  860. X28 27.992 0 0
  861. X29 24.895 1.191 0
  862. X30 22.274 1.489 0
  863. X31 18.939 1.787 0
  864. X32 18.463 2.144 0
  865. X33 5.598 4.765 0
  866. X34 -4.169 4.765 0
  867. X35 -4.169 3.573 0
  868. X36 -10.923 3.573 0
  869. X37 -17.272 3.573 0
  870. X38 -17.272 2.382 0
  871. X39 -13.698 2.382 0
  872. X40 -15.187 2.085 0
  873. X41 -18.165 1.191 0
  874. X42 -18.165 0 0
  875. X43 5.598 4.765 0
  876. X44 -2.978 15.008 0
  877. X45 0.357 15.187 0
  878. X46 0.357 15.485 0
  879. X47 -6.551 15.485 0
  880. X48 -6.551 3.573 0
  881. X49 -4.169 3.573 0
  882. X50 -4.169 4.765 0
  883. X51 -10.923 3.573 0
  884. X52 -15.187 8.934 0.893
  885. X53 -17.272 8.934 0.893
  886. X54 -17.272 3.573 0
  887. X55 27.992 0 0
  888. X56 23.525 0 -1.191
  889. X57 17.272 0 -2.382
  890. X58 15.783 0 -3.812
  891. X59 13.996 0 -4.169
  892. X60 11.316 0 -4.05
  893. X61 8.338 0 -3.335
  894. X62 1.787 0 -2.382
  895. X63 -4.169 0 -2.382
  896. X64 -13.936 0 -1.906
  897. X65 -15.128 0 -1.906
  898. X66 -15.187 0 -1.787
  899. X67 -18.165 0 -1.191
  900. X68 -18.165 0 0
  901. X69 -4.169 0 -2.382
  902. X70 -10.125 0 -4.05
  903. X71 -15.783 0 -10.482
  904. X72 -19.654 0 -10.482
  905. X73 -19.654 0 -9.529
  906. X74 -19.654 0 -9.529
  907. X75 -16.378 0 -3.573
  908. X76 -16.378 0 -2.144
  909. X77 -14.889 0 -2.382
  910. X78 -13.936 0 -2.382
  911. X79 -13.936 0 -1.906
  912. X80 -18.165 0 0
  913. X81 -18.165 0 1.191
  914. X82 -15.187 0 2.085
  915. X83 -13.698 0 2.263
  916. X84 -2.68 0 2.382
  917. X85 8.04 0 2.382
  918. X86 12.507 0 2.263
  919. X87 12.507 0 0.596
  920. X88 19.952 0 0.596
  921. X89 23.525 0 0.476
  922. X90 27.992 0 0
  923. X91 -3.551 0 -2.382
  924. X92 -3.551 -3.871 -0.10
  925. X93 -3.551 -15.485 0
  926. X94 -3.551 -15.485 0.1065
  927. X95 -3.551 -3.871 0.142
  928. X96 -3.551 -2.58 0.2556
  929. X97 -3.551 -2.387 1.818
  930. X98 -3.551 -2.102 2.015
  931. X99 -3.551 -1.03 2.251
  932. X100 -3.551 0 2.282
  933. X101 -3.551 1.03 2.251
  934. X102 -3.551 2.102 2.015
  935. X103 -3.551 2.387 1.818
  936. X104 -3.551 2.58 0.2556
  937. X105 -3.551 3.871 0.142
  938. X106 -3.551 15.485 0.1065
  939. X107 -3.551 15.485 0
  940. X108 -3.551 3.871 -0.10
  941. X109 13.996 0 -4.169
  942. X110 13.996 -0.8932 -3.692
  943. X111 13.996 -1.191 -2.978
  944. X112 13.996 -1.251 -2.502
  945. X113 13.996 -1.787 -1.311
  946. X114 13.996 -3.054 0
  947. X115 13.996 -1.583 0.3568
  948. X116 13.996 0 0.596
  949. X117 13.996 1.583 0.3568
  950. X118 13.996 3.054 0
  951. X119 13.996 1.787 -1.311
  952. X120 13.996 1.251 -2.502
  953. X121 13.996 1.191 -2.978
  954. X122 13.996 0.8932 -3.692
  955. Xgray 14 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  956. Xgray 18 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  957. Xgray 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  958. Xgray 8 16 17 18 19 20 21 22 23
  959. Xgray 4 24 25 26 27
  960. Xgray 15 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  961. Xgray 8 43 44 45 46 47 48 49 50
  962. Xgray 4 51 52 53 54
  963. Xgray 14 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  964. Xgray 11 69 70 71 72 73 74 75 76 77 78 79
  965. Xgray 11 80 81 82 83 84 85 86 87 88 89 90
  966. *-*-END-of-./V/test/hold-*-*
  967. echo x - ./fsim
  968. sed 's/^X//' >./fsim <<'*-*-END-of-./fsim-*-*'
  969. *-*-END-of-./fsim-*-*
  970. echo x - ./fsim/pm.c
  971. sed 's/^X//' >./fsim/pm.c <<'*-*-END-of-./fsim/pm.c-*-*'
  972. X/*
  973. X *    xflight : an aerial combat simulator for X
  974. X *
  975. X *    Written by Riley Rainey,  riley@mips.com
  976. X *
  977. X *    Permission to use, copy, modify and distribute (without charge) this
  978. X *    software, documentation, images, etc. is granted, provided that this 
  979. X *    comment and the author's name is retained.
  980. X *
  981. X */
  982. X#include <stdio.h>
  983. X#include <math.h>
  984. X#include "pm.h"
  985. X
  986. Xint debug = 0;
  987. X
  988. X/*
  989. X *  A Flight Simulator
  990. X *
  991. X *  Riley Rainey
  992. X */
  993. X
  994. X/*
  995. X *  We keep a table of atmospheric constants for different altitudes.
  996. X *  These values are important to flight calculations.
  997. X */
  998. X
  999. Xstruct {
  1000. X    double    alt;        /* altitude in feet */
  1001. X    double    rho;        /* rho value (air density) */
  1002. X    double    speedOfSound;    /* speed of sound in feet per second */
  1003. X    } *rhop, rhoTable[] = {
  1004. X    0.0, 23.77, 1116.9,
  1005. X    2.0, 22.41, 1109.2,
  1006. X    4.0, 21.11, 1101.4,
  1007. X    6.0, 19.87, 1093.6,
  1008. X    8.0, 18.68, 1085.7,
  1009. X    10.0, 17.55, 1077.8,
  1010. X    15.0, 14.96, 1057.7,
  1011. X    20.0, 12.66, 1037.3,
  1012. X    25.0, 10.65, 1016.4,
  1013. X    30.0,  8.89,  995.1,
  1014. X    35.0,  7.365, 973.3,
  1015. X    40.0,  5.851, 968.5,
  1016. X    50.0,  3.618, 968.5,
  1017. X    60.0,  2.238, 968.5,
  1018. X    80.0,  0.9065, 980.0,
  1019. X    100.0, 0.3371, 1015.0,
  1020. X    120.0, 0.1340, 1053.0,
  1021. X    160.0, 0.02622, 1083.0,
  1022. X    100000.0, 0.02622, 1083.0};    /* a large value for alt at the end */
  1023. X
  1024. Xdouble        deltaT;        /* Update interval in seconds */
  1025. Xdouble        halfDeltaTSquared; /* 0.5 * deltaT * deltaT */
  1026. Xdouble        CM, CN;
  1027. X
  1028. X/*
  1029. X *  calcRho : Calculate air density by interpolation.
  1030. X */
  1031. X
  1032. Xdouble calcRho (alt)
  1033. Xdouble alt; {
  1034. X
  1035. X    double    deltaAlt, b;
  1036. X
  1037. X    alt = alt / 1000.0;
  1038. X
  1039. X    for (rhop=rhoTable; alt>rhop->alt; ++rhop) ;
  1040. X    deltaAlt = (rhop+1)->alt - rhop->alt;
  1041. X    b = ((rhop+1)->rho - rhop->rho) / deltaAlt;
  1042. X    return (rhop->rho + b * (alt - rhop->alt)) / 10000.0;
  1043. X
  1044. X}
  1045. X
  1046. X/*
  1047. X *  calcCoefficients :  Calculate CLift and friends
  1048. X */
  1049. X
  1050. Xvoid calcCoefficients (c, CLift, CDrag)
  1051. Xcraft     *c;
  1052. Xdouble  *CLift, *CDrag; {
  1053. X
  1054. X    double CDAlpha, CDBeta;
  1055. X
  1056. X/*
  1057. X *  We used to interpolate these values, but now use several characteristic
  1058. X *  equations to compute these values for a given alpha value. The basic
  1059. X *  formulas are:
  1060. X *
  1061. X *
  1062. X *   C  = C        + (alpha * (C       + sin(curFlap) * cFlap ))
  1063. X *    L    LOrigin            LSlope
  1064. X *
  1065. X *
  1066. X *   C  = C        + (C       * Cos (alpha + C      ))
  1067. X *    D    DOrigin     DFactor                DPhase
  1068. X *
  1069. X *  There are independent equations defining drag resulting from alpha
  1070. X *  and beta values.  The hypoteneuse of those two values becomes the
  1071. X *  resultant CDrag value.
  1072. X */
  1073. X
  1074. X    if (c->alpha < c->cinfo->CLNegStall || c->alpha > c->cinfo->CLPosStall) {
  1075. X
  1076. X        *CLift = 0.0;
  1077. X        CM = c->cinfo->cmFactor * sin (c->alpha);
  1078. X    }
  1079. X    else {
  1080. X        *CLift = c->cinfo->CLOrigin + 
  1081. X            (c->cinfo->CLSlope + sin (c->curFlap) * c->cinfo->cFlap)
  1082. X            * c->alpha;
  1083. X        CM = (c->alpha - c->Se * c->cinfo->effElevator) * c->cinfo->cmSlope;
  1084. X    }
  1085. X
  1086. X/*    CDAlpha = c->cinfo->CDOrigin + c->cinfo->CDFactor * 
  1087. X        cos (c->alpha + c->cinfo->CDPhase);
  1088. X*/
  1089. X
  1090. X    CDAlpha = c->cinfo->CDOrigin + 
  1091. X        *CLift * *CLift / (pi * c->cinfo->aspectRatio);
  1092. X    CDAlpha += sin (c->curSpeedBrake) * c->cinfo->cSpeedBrake;
  1093. X
  1094. X    if (fabs(c->beta) > c->cinfo->betaStall)
  1095. X        CN = c->cinfo->cnFactor * sin (c->beta);
  1096. X    else
  1097. X        CN = (c->beta - c->Sr) * c->cinfo->cnSlope;
  1098. X
  1099. X    CDBeta = c->cinfo->CDBOrigin + c->cinfo->CDBFactor * 
  1100. X        cos (c->beta + c->cinfo->CDBPhase);
  1101. X
  1102. X    *CDrag = sqrt (CDAlpha * CDAlpha + CDBeta * CDBeta);
  1103. X
  1104. X}
  1105. X
  1106. Xdouble heading (x)
  1107. XVPoint    *x; {
  1108. X
  1109. X    double    m;
  1110. X
  1111. X    if (x->x == 0.0 && x->y == 0.0)
  1112. X        return 0.0;
  1113. X
  1114. X    if ((m = atan2 (x->y, x->x)) < 0.0)
  1115. X        return (pi * 2.0 + m);
  1116. X    else
  1117. X        return m;
  1118. X}
  1119. X
  1120. Xvoid pitchAndRoll (x, y, p, r)
  1121. XVPoint    *x;
  1122. XVPoint  *y;
  1123. Xdouble    *p;
  1124. Xdouble    *r; {
  1125. X
  1126. X    double    h;
  1127. X
  1128. X    h = sqrt (x->x * x->x + x->y * x->y);
  1129. X/*
  1130. X *  Is all this needed?
  1131. X */
  1132. X    if (h == 0.0)
  1133. X        if (x->z > 0.0)
  1134. X            *p = pi * 0.5;
  1135. X        else
  1136. X            *p = - pi * 0.5;
  1137. X    else
  1138. X        *p = atan2 (x->z, h);
  1139. X
  1140. X    h = sqrt (y->x * y->x + y->y * y->y);
  1141. X    *r = atan2 (y->z, h);
  1142. X}
  1143. X
  1144. Xvoid craftToGround (c, p, g)
  1145. Xcraft  *c;
  1146. XVPoint *p;
  1147. XVPoint *g; {
  1148. X
  1149. X    VTransform (p, &(c->trihedral), g);
  1150. X
  1151. X}
  1152. X
  1153. Xvoid calcGForces (c, f, w)
  1154. Xcraft *c;
  1155. XVPoint *f;
  1156. Xdouble w; {
  1157. X
  1158. X    VPoint t;
  1159. X
  1160. X    t = *f;
  1161. X    t.z -= w;
  1162. X
  1163. X    VTransform (&t, &(c->Itrihedral), &(c->G));
  1164. X    c->G.x = - c->G.x / w;
  1165. X    c->G.y = - c->G.y / w;
  1166. X    c->G.z = - c->G.z / w;
  1167. X}
  1168. X
  1169. Xvoid calcAlphaBeta (c, alpha, beta)
  1170. Xcraft *c;
  1171. Xdouble *alpha, *beta; {
  1172. X
  1173. X    VPoint    C;
  1174. X    double    h;
  1175. X
  1176. X    if (mag(c->Cg) > 0.0) {
  1177. X        VTransform (&(c->Cg), &(c->Itrihedral), &C);
  1178. X        *alpha = atan2 (C.z, C.x);
  1179. X        h = sqrt (C.z * C.z + C.x * C.x);
  1180. X        *beta = atan2 (C.y, h);
  1181. X    }
  1182. X    else {
  1183. X        *alpha = 0.0;
  1184. X        *beta = 0.0;
  1185. X    }
  1186. X
  1187. X}
  1188. X
  1189. X/*
  1190. X *  buildEulerMatrix :  Build a transformation matrix based on the supplied
  1191. X *            euler angles.
  1192. X */
  1193. X
  1194. Xvoid buildEulerMatrix (roll, pitch, heading, m)
  1195. Xdouble    roll, pitch, heading;
  1196. XVMatrix    *m; {
  1197. X
  1198. X    VIdentMatrix (m);
  1199. X    if (roll != 0.0)
  1200. X        VRotate (m, XRotation, roll);
  1201. X    if (pitch != 0.0)
  1202. X                VRotate (m, YRotation, -pitch);
  1203. X    if (heading != 0.0)
  1204. X                VRotate (m, ZRotation, heading);
  1205. X}
  1206. X
  1207. Xint  flightCalculations (c)
  1208. Xcraft *c; {
  1209. X
  1210. X    double    q, CLift, CDrag;
  1211. X    double    FLift, FDrag, FWeight;
  1212. X    double    Vmag, D, angle;
  1213. X    double    ar, ap, aq, cosR, sinR;
  1214. X    double  deltaRoll, deltaPitch, deltaYaw;
  1215. X    double    muStatic, muKinetic;
  1216. X    double    ke, be;
  1217. X    VPoint    F, Fg, V, tmpPt, r;
  1218. X    VMatrix turn, tmpMatrix, mtx;
  1219. X    int    positionUpdated = 0;
  1220. X
  1221. X    c->prevSg = c->Sg;
  1222. X
  1223. X    c->rho = calcRho (-(c->Sg.z));
  1224. X    calcAlphaBeta(c, &(c->alpha), &(c->beta));
  1225. X
  1226. X/*
  1227. X *  A note about thrust:  Normal thrust deminishes in proportion to the decrease in
  1228. X *  air density.  Afterburners are not affectected in this way.  The following formula
  1229. X *  approximates this effect.
  1230. X */
  1231. X
  1232. X    c->curThrust = calcThrust(c);
  1233. X    calcCoefficients (c, &CLift, &CDrag);
  1234. X
  1235. X    if (debug)
  1236. X    printf ("alpha = %g, beta = %g\nCL = %g, CD = %g\n", RADtoDEG(c->alpha),
  1237. X        RADtoDEG(c->beta), CLift, CDrag);
  1238. X
  1239. X
  1240. X/*
  1241. X *  Compute the resultant force vector on the aircraft.
  1242. X */
  1243. X
  1244. X    Vmag = mag(c->Cg);
  1245. X    q = c->rho * c->cinfo->wingS * Vmag * Vmag * 0.5;
  1246. X    FLift = CLift * q;
  1247. X    FDrag = CDrag * q;
  1248. X
  1249. X    if (debug) {
  1250. X    printf ("rho = %g, FLift = %g, FDrag = %g\n", c->rho, FLift, FDrag);
  1251. X    printf ("FThrust = %g\n", c->curThrust);
  1252. X    }
  1253. X
  1254. X    F.x = c->curThrust - sin(c->alpha) * cos(c->beta) * FLift -
  1255. X        cos(c->alpha) * cos(c->beta) * FDrag;
  1256. X    F.y = sin(c->alpha) * sin(c->beta) * FLift - sin(c->alpha) * sin(c->beta) *
  1257. X        FDrag;
  1258. X    F.z = -cos(c->alpha) * cos(c->beta) * FLift - sin(c->alpha) * cos(c->beta) *
  1259. X        FDrag;
  1260. X
  1261. X/*
  1262. X *  Get ground friction coefficients
  1263. X */
  1264. X
  1265. X    if (c->groundContact)
  1266. X    if (c->flags & FL_BRAKES) {
  1267. X        muStatic = c->cinfo->muBStatic;
  1268. X        muKinetic = c->cinfo->muBKinetic;
  1269. X    }
  1270. X    else {
  1271. X        muStatic = c->cinfo->muStatic;
  1272. X        muKinetic = c->cinfo->muKinetic;
  1273. X    }
  1274. X
  1275. X/*
  1276. X *  Now calculate changes in position (Sg) and velocity (Cg).
  1277. X */
  1278. X
  1279. X    if (Vmag > c->cinfo->maxNWS || c->groundContact == 0)
  1280. X        c->flags &= ~FL_NWS;
  1281. X    else
  1282. X        c->flags |= FL_NWS;
  1283. X
  1284. X    if (c->flags & FL_NWS) {
  1285. X
  1286. X        c->curNWDef = c->Sa * c->cinfo->maxNWDef;
  1287. X
  1288. X        if (c->curNWDef != 0.0) {
  1289. X
  1290. X        r.x = c->cinfo->gearD2;
  1291. X        r.y = c->cinfo->gearD1 / tan(c->curNWDef);
  1292. X        r.z = 0.0;
  1293. X        angle = Vmag / r.y * deltaT;
  1294. X
  1295. X/*
  1296. X *  Nose wheel steering mode.
  1297. X *  Relocate the aircraft and its trihedral (this code assumes that the
  1298. X *  plane is rolling on a flat surface (i.e. z is constant).
  1299. X */
  1300. X
  1301. X        tmpPt = r;
  1302. X        VTransform(&tmpPt, &(c->trihedral), &r);
  1303. X
  1304. X        VIdentMatrix (&turn);
  1305. X        turn.m[0][3] = - c->Sg.x - r.x;
  1306. X        turn.m[1][3] = - c->Sg.y - r.y;
  1307. X        turn.m[2][3] = - c->Sg.z;
  1308. X        VRotate (&turn, ZRotation, angle);
  1309. X        turn.m[0][3] = turn.m[0][3] + c->Sg.x + r.x;
  1310. X        turn.m[1][3] = turn.m[1][3] + c->Sg.y + r.y;
  1311. X        turn.m[2][3] = turn.m[2][3] + c->Sg.z;
  1312. X        VTransform (&(c->Sg), &turn, &tmpPt);
  1313. X        c->Sg = tmpPt;
  1314. X
  1315. X        VIdentMatrix (&turn);
  1316. X        VRotate (&turn, ZRotation, angle);
  1317. X        tmpMatrix = c->trihedral;
  1318. X        VMatrixMult (&tmpMatrix, &turn, &(c->trihedral));
  1319. X        VTransform (&(c->Cg), &turn, &tmpPt);
  1320. X        c->Cg = tmpPt;
  1321. X
  1322. X            transpose (&c->trihedral, &c->Itrihedral);
  1323. X
  1324. X        addHeading (c, angle);
  1325. X        positionUpdated = 1;
  1326. X        }
  1327. X
  1328. X        craftToGround (c, &F, &Fg);
  1329. X        FWeight = c->cinfo->emptyWeight + c->fuel;
  1330. X
  1331. X        if ((c->fuel -= fuelUsed(c)) <= 0.0) {
  1332. X        c->fuel = 0.0;
  1333. X        c->curThrust = 0.0;
  1334. X        c->throttle = 0;
  1335. X        }
  1336. X
  1337. X        Fg.z += FWeight;
  1338. X
  1339. X/*
  1340. X *  Factor in ground friction for both static and moving planes.
  1341. X */
  1342. X
  1343. X        if (c->Cg.x + c->Cg.y == 0.0 && sqrt (Fg.x*Fg.x + Fg.y*Fg.y) <=
  1344. X        muStatic * Fg.z) {
  1345. X            Fg.x = 0.0;
  1346. X            Fg.y = 0.0;
  1347. X        }
  1348. X        else {
  1349. X
  1350. X/*
  1351. X *  Okay, the plane is moving.  Quantify the current kinetic energy of the
  1352. X *  moving craft and add the energy added this period by all forces EXCEPT
  1353. X *  ground friction (we'll name this "ke").  If the energy removed by the friction
  1354. X *  force is greater than ke, then the craft will stop sometime during this
  1355. X *  period -- we won't bother to calculate exactly where we stop; just zero out
  1356. X *  the x and y force and velocity components.
  1357. X */
  1358. X
  1359. X        ke = 0.5 * FWeight / a * sqrt (c->Cg.x * c->Cg.x +
  1360. X            c->Cg.y * c->Cg.y);
  1361. X        ke += pow(sqrt(Fg.x * Fg.x + Fg.y * Fg.y), 2.0) *
  1362. X            halfDeltaTSquared * a / FWeight;
  1363. X        be = pow(Fg.z * muKinetic, 2.0) * halfDeltaTSquared * a / FWeight;
  1364. X        if (be >= ke) {
  1365. X            Fg.x = 0.0;
  1366. X            Fg.y = 0.0;
  1367. X            c->Cg.x = 0.0;
  1368. X            c->Cg.y = 0.0;
  1369. X        }
  1370. X        else {
  1371. X
  1372. X/*
  1373. X *  Getting to this point means that we're rolling along the ground (and not stopping)
  1374. X *  -- make sure our roll is zeroed, then cancel the local Y-component of our
  1375. X *  velocity vector (tires don't roll sideways) and then calculate the drag
  1376. X *  contributed by the rolling wheels.
  1377. X */
  1378. X
  1379. X            c->curRoll = 0.0;
  1380. X            VTransform (&(c->Cg), &(c->Itrihedral), &V);
  1381. X            V.y = 0.0;
  1382. X            VTransform (&V, &(c->trihedral), &(c->Cg));
  1383. X            D = Fg.z * muKinetic;
  1384. X            Vmag = mag (c->Cg);
  1385. X            if (Vmag > 0.0) {
  1386. X                Fg.x -= D * c->Cg.x / Vmag;
  1387. X                Fg.y -= D * c->Cg.y / Vmag;
  1388. X                Fg.z -= D * c->Cg.z / Vmag;
  1389. X            }
  1390. X        }
  1391. X        }
  1392. X
  1393. X
  1394. X/* Nose wheel steering is only active when we cannot lift off -- cancel z */
  1395. X
  1396. X        Fg.z = 0.0;
  1397. X        calcGForces (c, &Fg, FWeight);
  1398. X
  1399. X    }
  1400. X    else {
  1401. X
  1402. X/*
  1403. X *  Resolve moments
  1404. X */
  1405. X
  1406. X        ap = fsign (c->p);
  1407. X        aq = fsign (c->q);
  1408. X        ar = fsign (c->r);
  1409. X        if (c->groundContact == 0) {
  1410. X        ap = (c->Sa * c->cinfo->effAileron * q - c->cinfo->LDamp *
  1411. X            ap * c->p * c->p * 0.5) / c->cinfo->I.m[0][0];
  1412. X            ap += c->beta * c->cinfo->CLbeta * q / c->cinfo->I.m[0][0];
  1413. X        }
  1414. X        else
  1415. X        ap = 0.0;
  1416. X
  1417. X        aq = (CM * q - c->cinfo->MDamp * aq * c->q * c->q * 0.5) /
  1418. X        c->cinfo->I.m[1][1];
  1419. X        ar = (CN * q - c->cinfo->NDamp * ar * c->r * c->r * 0.5) /
  1420. X        c->cinfo->I.m[2][2];
  1421. X
  1422. X        if (debug)
  1423. X        printf ("ap = %g, aq = %g, ar = %g\n", ap, aq, ar);
  1424. X
  1425. X        deltaRoll  = c->p * deltaT + ap * halfDeltaTSquared;
  1426. X        deltaPitch = c->q * deltaT + aq * halfDeltaTSquared;
  1427. X        deltaYaw   = c->r * deltaT + ar * halfDeltaTSquared;
  1428. X        c->p = c->p + ap * deltaT;
  1429. X        c->q = c->q + aq * deltaT;
  1430. X        c->r = c->r + ar * deltaT;
  1431. X
  1432. X        cosR = cos (c->curRoll);
  1433. X        sinR = sin (c->curRoll);
  1434. X
  1435. X      
  1436. X        c->curRoll    += deltaRoll;
  1437. X        c->curHeading += sinR * deltaPitch + cosR * deltaYaw;
  1438. X        c->curPitch   += cosR * deltaPitch - sinR * deltaYaw;
  1439. X
  1440. X/*
  1441. X *  Normalize picth and heading Euler angles
  1442. X */
  1443. X
  1444. X        if (c->curPitch > pi / 2.0) {
  1445. X        c->curPitch = pi - c->curPitch;    
  1446. X        c->curHeading = (c->curHeading > pi) ?
  1447. X            c->curHeading - pi : c->curHeading + pi;
  1448. X        c->curRoll = pi - c->curRoll;
  1449. X        }
  1450. X        else if (c->curPitch < -pi/2.0) {
  1451. X        c->curPitch = -pi - c->curPitch;
  1452. X        c->curHeading = (c->curHeading > pi) ?
  1453. X            c->curHeading - pi : c->curHeading + pi;
  1454. X        c->curRoll = pi - c->curRoll;
  1455. X            }
  1456. X
  1457. X        if (c->curHeading < 0.0) {
  1458. X        c->curHeading += 2.0 * pi;
  1459. X        }
  1460. X        else if (c->curHeading > 2.0 * pi) {
  1461. X        c->curHeading -= 2.0 * pi;
  1462. X        }
  1463. X
  1464. X/*
  1465. X *  Compute transformation matrices
  1466. X */
  1467. X
  1468. X        buildEulerMatrix (c->curRoll, c->curPitch, c->curHeading, &(c->trihedral));
  1469. X        transpose (&c->trihedral, &c->Itrihedral);
  1470. X
  1471. X        craftToGround (c, &F, &Fg);
  1472. X        FWeight = c->cinfo->emptyWeight + c->fuel;
  1473. X
  1474. X        if ((c->fuel -= fuelUsed(c)) <= 0.0) {
  1475. X        c->fuel = 0.0;
  1476. X        c->curThrust = 0.0;
  1477. X        }
  1478. X
  1479. X        Fg.z += FWeight;
  1480. X
  1481. X/*
  1482. X *  If we are on the ground, level the wings and compute wheel drag forces.  Wheel
  1483. X *  drag always acts in the opposite direction of the velocity vector.
  1484. X */
  1485. X
  1486. X        if (c->groundContact) {
  1487. X        c->curRoll = 0.0;
  1488. X        VTransform (&(c->Cg), &(c->Itrihedral), &V);
  1489. X        V.y = 0.0;
  1490. X        VTransform (&V, &(c->trihedral), &(c->Cg));
  1491. X        D = Fg.z * muKinetic;
  1492. X        Vmag = mag (c->Cg);
  1493. X        Fg.x -= D * c->Cg.x / Vmag;
  1494. X        Fg.y -= D * c->Cg.y / Vmag;
  1495. X        Fg.z -= D * c->Cg.z / Vmag;
  1496. X        }
  1497. X
  1498. X        if (debug) {
  1499. X            printf ("v = %g, Fg = { %g, %g, %g }\n", FPStoKTS(Vmag),
  1500. X            Fg.x, Fg.y, Fg.z);
  1501. X            printf ("F = { %g, %g, %g }\n",
  1502. X            F.x, F.y, F.z);
  1503. X        }
  1504. X
  1505. X
  1506. X/*
  1507. X *  Are we on the ground without the prospect of gaining altitude?
  1508. X *  If so, cancel the vertical force component.
  1509. X */
  1510. X
  1511. X        if (c->groundContact && Fg.z > 0.0)
  1512. X        Fg.z = 0.0;
  1513. X
  1514. X        calcGForces (c, &Fg, FWeight);
  1515. X
  1516. X
  1517. X    }
  1518. X
  1519. X/*
  1520. X *  Update our position (in flight mode).
  1521. X */
  1522. X
  1523. X    if (positionUpdated == 0) {
  1524. X
  1525. X        c->Sg.x += c->Cg.x * deltaT + Fg.x / FWeight
  1526. X            * a * halfDeltaTSquared;
  1527. X        c->Sg.y += c->Cg.y * deltaT + Fg.y / FWeight
  1528. X            * a * halfDeltaTSquared;
  1529. X        c->Sg.z += c->Cg.z * deltaT + Fg.z / FWeight
  1530. X            * a * halfDeltaTSquared;
  1531. X
  1532. X    }
  1533. X
  1534. X    c->Cg.x += Fg.x / FWeight * a * deltaT;
  1535. X    c->Cg.y += Fg.y / FWeight * a * deltaT;
  1536. X    c->Cg.z += Fg.z / FWeight * a * deltaT;
  1537. X
  1538. X    if (debug) {
  1539. X        printf ("Altitude = %g\n", -c->Sg.z);
  1540. X        printf ("Euler angles { %g, %g, %g }\n", RADtoDEG(c->curRoll),
  1541. X            RADtoDEG(c->curPitch), RADtoDEG(c->curHeading));
  1542. X        printf ("Cg = { %g, %g, %g }\n", c->Cg.x, c->Cg.y, c->Cg.z);
  1543. X        printf ("Sg = { %g, %g, %g }\n", c->Sg.x, c->Sg.y, c->Sg.z);
  1544. X
  1545. X        printf ("X = { %g, %g, %g }\n", c->trihedral.m[0][0],
  1546. X            c->trihedral.m[1][0], c->trihedral.m[2][0]);
  1547. X        printf ("Z = { %g, %g, %g }\n\n", c->trihedral.m[0][2],
  1548. X            c->trihedral.m[1][2], c->trihedral.m[2][2]);
  1549. X    }
  1550. X
  1551. X
  1552. X/*
  1553. X *  Normalize the vertical position.  If our altitude is now below our
  1554. X *  contact threshold, mark us as having "groundContact" and adjust the
  1555. X *  altitude.
  1556. X */
  1557. X
  1558. X    if (c->Sg.z >= - c->cinfo->groundingPoint.z) {
  1559. X        c->groundContact = 1;
  1560. X        c->Sg.z = - c->cinfo->groundingPoint.z;
  1561. X
  1562. X/*
  1563. X *  If the vertical velocity component is too great, the plane has crashed ...
  1564. X */
  1565. X
  1566. X        if (c->Cg.z > c->cinfo->crashC)
  1567. X            return 1;
  1568. X        else
  1569. X            c->Cg.z = 0.0;
  1570. X
  1571. X    }
  1572. X    else {
  1573. X        c->groundContact = 0;
  1574. X        c->flags &= ~FL_NWS;
  1575. X    }
  1576. X
  1577. X
  1578. X    return 0;
  1579. X}
  1580. *-*-END-of-./fsim/pm.c-*-*
  1581. echo x - ./fsim/pm.h
  1582. sed 's/^X//' >./fsim/pm.h <<'*-*-END-of-./fsim/pm.h-*-*'
  1583. X#include "manifest.h"
  1584. X#include "eng.xbm"
  1585. X#include "flaps0.xbm"
  1586. X#include "flaps1.xbm"
  1587. X#include "flaps2.xbm"
  1588. X#include "flaps3.xbm"
  1589. X#include "scale.h"
  1590. X#include <Vlib.h>
  1591. X
  1592. X#define MAXSURFACE    8
  1593. X#define MAXPLAYERS    16
  1594. X#define MAXPROJECTILES    MAXPLAYERS*8
  1595. X#define MAXCRAFTTYPES    16
  1596. X#define STATIONS    9
  1597. X#define WEAPONTYPES    4
  1598. X
  1599. Xtypedef struct _viewer {
  1600. X    struct _viewer *next;
  1601. X    Display            *dpy;        /* display for this user */
  1602. X    Window        win;        /* window for this user */
  1603. X    Window        twin, rwin;    /* threat window and radar window */
  1604. X    GC        gc;        /* GC for drawing */
  1605. X    XFontStruct    *font;        /* HUD font */
  1606. X    XFontStruct    *rfont;        /* radar font */
  1607. X    Viewport    *v;        /* Viewport for out-of-cockpit views */
  1608. X    Pixmap        eng;        /* Engine "RPM" gauge */
  1609. X    Pixmap        flap[5];    /* flap setting indicators */
  1610. X    int        cn;        /* X connection fd */
  1611. X    int        width, height;    /* width & height of viewing window */
  1612. X    int        xCenter, yCenter; /* center of viewing window */
  1613. X    int        ftw, fth;    /* HUD font width & height */
  1614. X    int        rftw, rfth;
  1615. X    int        radarWidth;
  1616. X    int        radarHeight;
  1617. X    scaleControl    altScale;    /* altitude scale control */
  1618. X    scaleControl    velScale;    /* airspeed scale control */
  1619. X    scaleControl    hdgScale;    /* heading scale control */
  1620. X    int        TEWSx, TEWSy;    /* location of center of TEWS display */
  1621. X    int        TEWSSize;    /* size of TEWS display, in pixels */
  1622. X    }        viewer;
  1623. X
  1624. X/*
  1625. X *  This structure describes a class of aircraft.
  1626. X */
  1627. X
  1628. Xtypedef struct {
  1629. X    char    *name;        /* name of aircraft class */
  1630. X
  1631. X    double    aspectRatio;    /* wing aspect ratio */
  1632. X
  1633. X    double    CLOrigin, CLSlope; /* Defines the CL characteristic eqn */
  1634. X    double    CLNegStall, CLPosStall;
  1635. X    double    betaStall;    /* Stall angle for rudder */
  1636. X    double  CDOrigin, CDFactor; /* Defines the CD Characteristic eqn */
  1637. X    double  CDPhase;
  1638. X    double  CDBOrigin, CDBFactor; /* Defines the CD Characteristic eqn */
  1639. X    double  CDBPhase;
  1640. X    double    CLbeta;            /* coefficient rolling moment due to sideslip */
  1641. X    double  CMOrigin, CMFactor; /* Defines the CM Characteristic eqn */
  1642. X    double  CNOrigin, CNFactor; /* Defines the CM Characteristic eqn */
  1643. X
  1644. X    double    effAileron;    /* Aileron effectiveness */
  1645. X    double    effElevator;    /* Elevator effectiveness */
  1646. X    double    effRudder;    /* Rudder effectiveness */
  1647. X
  1648. X    VMatrix I;        /* Moments of Intertia about CG in [xyz] */
  1649. X    double    LDamp;        /* roll damping factor */
  1650. X    double    MDamp;        /* pitch damping factor */
  1651. X    double    NDamp;        /* yaw damping factor */
  1652. X    double    cmSlope; 
  1653. X    double  cmFactor;
  1654. X    double    cnSlope;
  1655. X    double    cnFactor;
  1656. X
  1657. X    double    maxFlap;    /* maximum flap setting (radians) */
  1658. X    double    cFlap;        /* lift coefficient of flaps */
  1659. X    double    flapRate;    /* flap movement rate (radians/sec) */
  1660. X
  1661. X    double    maxSpeedBrake;    /* maximum speed brake setting (radians) */
  1662. X    double    cSpeedBrake;    /* drag coefficient of 90 degree speed brake */
  1663. X    double    speedBrakeRate;    /* rate of speed brake movement (radians/sec) */
  1664. X    double    speedBrakeIncr;    /* number of radians than one keystroke moves brake */
  1665. X
  1666. X    double    wingS;        /* wing area (ft^2) */
  1667. X    double    emptyWeight;    /* empty weight (lbs.) */
  1668. X    double    maxFuel;    /* maximum internal fuel (lbs.) */
  1669. X
  1670. X    double  maxThrust;    /* maximum thrust, military power (lb) */
  1671. X    double  maxABThrust;    /* maximum thrust, afterburner on  (lb) */
  1672. X    double  spFuelConsump;    /* specific fuel consump(lb fuel/lb T x hr)*/
  1673. X    double    spABFuelConsump;
  1674. X    VPoint    groundingPoint;    /* hypothetical single pt of contact w/ground */
  1675. X    VPoint  viewPoint;    /* pilot's viewing location wrt CG */
  1676. X    double    crashC;        /* maximum tolerable touchdown z component */
  1677. X
  1678. X    double    muStatic;    /* static coefficient of friction no-brakes */
  1679. X    double    muKinetic;    /* moving coefficient of friction no-brakes */
  1680. X    double    muBStatic;    /* static brakes-on */
  1681. X    double  muBKinetic;    /* kinetic brakes-on */
  1682. X
  1683. X    double  maxNWDef;    /* maximum nosewheel deflection (radians) */
  1684. X    double  NWIncr;        /* deflection for each unit */
  1685. X    double  maxNWS;        /* maximum NWS velocity */
  1686. X    double    gearD1;        /* x station wrt nose gear of main gear */
  1687. X    double  gearD2;        /* x station wrt CG of main gear */
  1688. X    double    armDelay;    /* arming delay for missiles */
  1689. X    double    radarOutput;    /* radar output (watts) */
  1690. X    double    radarTRange;    /* tracking radar range */
  1691. X    double    radarDRange;    /* detection radar range */
  1692. X    double    TEWSThreshold;
  1693. X
  1694. X    int    sCount;        /* number of weapon stations */
  1695. X    VPoint    wStation[STATIONS]; /* weapon's stations (launch points) */
  1696. X
  1697. X    int    (*placeProc)();    /* object placement procedure (for special craft) */
  1698. X    VObject *object;    /* what it looks like */
  1699. X    }    craftType;
  1700. X
  1701. Xtypedef struct _wdsc {
  1702. X    int        mask;        /* key mask */
  1703. X    int        (*select)();    /* weapon select procedure */
  1704. X    int        (*update)();    /* per tick update procedure */
  1705. X    int        (*display)();    /* display update procedure */
  1706. X    int        (*firePress)();    /* fire button pressed procedure */
  1707. X    int        (*fireRelease)(); /* fire button released */
  1708. X    craftType    *w;        /* description of this weapon */
  1709. X    }        weaponDesc;
  1710. X
  1711. Xtypedef struct _wctl {
  1712. X    int        type;        /* type of weapon at this station */
  1713. X    int        info;        /* extra info (weapon specific) */
  1714. X    int        info2;        /* "      " */
  1715. X    int        info3;        /* "      " */
  1716. X    }        weaponStation;
  1717. X
  1718. X#define WK_M61A1    0x01        /* M-61A1 Vulcan 20mm cannon */
  1719. X#define WK_AIM9M    0x02        /* Sidewinder missile */
  1720. X
  1721. X/*
  1722. X *  This structure describes a particular instance of aircraft.
  1723. X */
  1724. X
  1725. Xtypedef struct _craft {
  1726. X    int    index;        /* index number of this element in the vector */
  1727. X    int    type;        /* craft type */
  1728. X    int    team;        /* team number */
  1729. X    double    createTime;    /* creation time of this craft */
  1730. X    viewer    *vl;        /* list of viewers */
  1731. X    VMatrix trihedral;      /* transforms [x, y, z] to Geoparallel */
  1732. X                /* x = forward, y=right wing, z=down */
  1733. X                /* does not include origin translation */
  1734. X    VMatrix    Itrihedral;    /* transforms geoparallel to [x, y, z] */
  1735. X    VPoint    C;        /* Velocity vector in [x, y, z] */
  1736. X    VPoint    Cg;        /* Velocity vector in Geoparallel system */
  1737. X    VPoint    Sg;        /* Position in Geoparallel system */
  1738. X    double    rho;        /* current rho value */
  1739. X    VPoint    G;        /* g-force vector in acft system */
  1740. X    VPoint    prevSg;        /* last interval's Sg value */
  1741. X    double    p, q, r;    /* roll, pitch, and yaw rates */
  1742. X    double    Se, Sa, Sr;    /* control settings */
  1743. X    double    curHeading, curPitch, curRoll; /* Euler angles for acft */
  1744. X    double    curThrust;    /* Current thrust value */
  1745. X    double    curFlap;    /* current flap setting (radians) */
  1746. X    double    flapSetting;    /* current target flap setting (radians) */
  1747. X    double    curSpeedBrake;    /* current speed brake position (radians) */
  1748. X    double    speedBrakeSetting; /* current target speed brake setting (radians) */
  1749. X    int    throttle;    /* thrust setting 0 - 32768 */
  1750. X    double    alpha, beta;    /* angles of attack and sideslip */
  1751. X    double    fuel;        /* current fuel on board */
  1752. X    int    groundContact;    /* 1, when on ground */
  1753. X    int    flags;        /* flag word */
  1754. X    int    radarMode;    /* radar mode */
  1755. X    double  curNWDef;    /* Current nosewheel deflection (radians) */
  1756. X    int    armFuse;    /* missile arming countdown */
  1757. X    craftType *cinfo;    /* General craft information */
  1758. X    double    order;        /* temporary value used to sort craft */
  1759. X    struct  _craft *next;    /* next craft in sorted list */
  1760. X    VPoint    viewDirection;    /* where the pilot is currently looking */
  1761. X    VPoint    viewUp;        /* the "up" direction of the pilot's view */
  1762. X
  1763. X    char    name[32];    /* logname of player */
  1764. X    char    display[32];    /* display name of player */
  1765. X
  1766. X    short    curRadarTarget;    /* our primary "threat" */
  1767. X    double    targetDistance; /* distance to primary target */
  1768. X    double    targetClosure;    /* closure rate on primary target */
  1769. X    short    relValid[MAXPLAYERS];
  1770. X    VPoint    relPos[MAXPLAYERS];
  1771. X    double    rval[MAXPLAYERS];/* radar strength seen by us from other craft */
  1772. X                /* relative positions of possible targets */
  1773. X    char    *leftHUD[3];    /* strings in lower left corner of HUD */
  1774. X                /* (reserved for weapons' status */
  1775. X    char    *rightHUD[3];    /* strings in lower right corner of HUD */
  1776. X                /* (reserved for future use) */
  1777. X    int    curWeapon;    /* index of currently selected weapon */
  1778. X    weaponStation station[STATIONS]; /* what's at each weapon station */
  1779. X    }    craft;
  1780. X
  1781. X/*
  1782. X *  We'll use some defines to reduce the storage required for the craft
  1783. X *  (unions would be cleaner, perhaps).
  1784. X */
  1785. X
  1786. X#define    rounds    curRadarTarget
  1787. X#define    tracerMod groundContact
  1788. X#define tracerVal radarMode
  1789. X
  1790. X/*
  1791. X *  Craft type definitions
  1792. X */
  1793. X
  1794. X#define CT_FREE        0    /* an unused craft entry */
  1795. X#define CT_PLANE    1    /* a player */
  1796. X#define CT_MISSILE    2    /* an air to air missile */
  1797. X#define CT_CANNON    3    /* a stream of cannon fire */
  1798. X#define CT_SURFACE    4    /* surface object (e.g. a runway) */
  1799. X#define CT_OBSERVER    5    /* a non-player "watcher" */
  1800. X#define CT_DRONE    6    /* a target drone */
  1801. X
  1802. X#define FL_RECORD    0x01    /* activate recording function */
  1803. X#define FL_AFTERBURNER    0x02    /* afterburner state */
  1804. X#define FL_BRAKES    0x04    /* wheel brake state */
  1805. X#define    FL_NWS        0x08    /* nose-wheel steering mode */
  1806. X#define FL_HAS_GYRO    0x10    /* missile is gyroscope equiped */
  1807. X
  1808. X#define RM_OFF        0    /* radar is off */
  1809. X#define RM_STANDBY    1    /* standby */
  1810. X#define RM_GUN_DIRECTOR    2    /* gun director mode */
  1811. X#define RM_HUD        3    /* 20 degree scan */
  1812. X#define RM_NORMAL    4    /* 65 degree scan */
  1813. X
  1814. Xint        recordCount;    /* number of players recording info */
  1815. Xdouble        curTime;    /* current time */
  1816. X
  1817. Xcraft        stbl[MAXSURFACE]; /* table of surface objects */
  1818. Xcraft        ptbl[MAXPLAYERS]; /* table of player aircraft */
  1819. Xcraft        mtbl[MAXPROJECTILES]; /* table of missiles and cannon streams */
  1820. XweaponDesc    wtbl[WEAPONTYPES]; /* descriptions of different weapons */
  1821. X
  1822. Xdouble        deltaT;        /* Update interval in seconds */
  1823. Xdouble        halfDeltaTSquared; /* 0.5 * deltaT * deltaT */
  1824. Xint        HUDPixel;    /* index of HUD color in viewport(s) */
  1825. XVColor        *HUDColor;
  1826. Xint        whitePixel;    /* index of white in viewport(s) */
  1827. XVColor        *whiteColor;    /* white in viewport(s) */
  1828. Xint        blackPixel;    /* index of black in viewport(s) */
  1829. XVColor        *blackColor;    /* black in viewport(s) */
  1830. XVColor        *groundColor;    /* ground color in viewport(s) */
  1831. X
  1832. X#define a    32.15        /* acceleration due to gravity (fps^2) */
  1833. X#define pi    3.1415927
  1834. X#define mag(v)    (sqrt (v.x * v.x + v.y * v.y + v.z * v.z))
  1835. X#define calcAplha(p)    (atan2 (p.C.z, p.C.x))
  1836. X#define calcBeta(p)    (atan2 (p.C.y, sqrt (pow (mag(p.C), 2.0) \
  1837. X            + p.C.y * p.C.y)))
  1838. X#define unitVector(v)    {double m; m = mag(v); \
  1839. X            v.x /= m; v.y /= m; v.z /= m; }
  1840. X
  1841. X#define addHeading(c, dh) {c->curHeading = c->curHeading + dh; \
  1842. X        if (c->curHeading > pi * 2.0 || c->curHeading <= 0.0) \
  1843. X            c->curHeading = (c->curHeading <= 0.0) ? c->curHeading + \
  1844. X            2.0 * pi : c->curHeading - 2.0 * pi; }
  1845. X
  1846. X#define NM        6076.115
  1847. X#define FPStoMPH(v)    (v / 5280.0 * 3600.0)
  1848. X#define FPStoKTS(v)    (v / 6076.115 * 3600.0)
  1849. X#define RADtoDEG(a)    (a * 180.0 / pi)
  1850. X#define DEGtoRAD(a)    (a * pi / 180.0)
  1851. X#define fsign(d)    (d < 0 ? -1.0 : 1.0)
  1852. X#define calcThrust(c)    ((((c->flags & FL_AFTERBURNER) ? \
  1853. X    c->cinfo->maxABThrust : c->cinfo->maxThrust) - \
  1854. X    c->cinfo->maxThrust * (1.0 - (c->rho / 0.002377))) * \
  1855. X    (double) c->throttle / 32768.0)
  1856. X#define fuelUsed(c)    (((c->flags & FL_AFTERBURNER) ? \
  1857. X    c->cinfo->spABFuelConsump : c->cinfo->spFuelConsump) * c->curThrust * \
  1858. X    deltaT / 3600.0)
  1859. X
  1860. X#define VIEW_WINDOW_HEIGHT    500
  1861. X#define VIEW_WINDOW_WIDTH    1200
  1862. X#define RADAR_WINDOW_WIDTH    200
  1863. X#define RADAR_WINDOW_HEIGHT    200
  1864. X#define RADAR_X            (1200/2-200/2)
  1865. X#define RADAR_Y            (500)
  1866. X#define TEWS_X            (1200/2-200/2-100)
  1867. X#define TEWS_Y            (VIEW_WINDOW_HEIGHT+60)
  1868. X#define TEWS_SIZE        81
  1869. X#define FS_WINDOW_WIDTH        (VIEW_WINDOW_WIDTH)    
  1870. X#define FS_WINDOW_HEIGHT     (VIEW_WINDOW_HEIGHT+RADAR_WINDOW_HEIGHT)
  1871. X#define    FLAP_X            (1200/2-200/2-95)
  1872. X#define FLAP_Y            (FS_WINDOW_HEIGHT-53)
  1873. X#define DESIGNATOR_SIZE        40
  1874. X
  1875. X/*
  1876. X *  Location of the center of the engine RPM gauge.
  1877. X */
  1878. X
  1879. X#define ENG_X            (FS_WINDOW_WIDTH-400)
  1880. X#define ENG_Y            (VIEW_WINDOW_HEIGHT+60)
  1881. X
  1882. X#define ALT_ORG_X        760
  1883. X#define ALT_ORG_Y        360
  1884. X#define ALT_LENGTH        199
  1885. X#define ALT_ORIENT        orientRight
  1886. X#define ALT_SCALE        (1700.0 / (double) ALT_LENGTH)
  1887. X#define ALT_INDEX_SIZE        30
  1888. X#define ALT_MIN_INTERVAL    100
  1889. X#define ALT_MIN_SIZE        8
  1890. X#define ALT_MAJ_INTERVAL    500
  1891. X#define ALT_MAJ_SIZE        15
  1892. X#define ALT_DIVISOR        1000.0
  1893. X#define ALT_FORMAT        "%4.3g"
  1894. X
  1895. X#define VEL_ORG_X        440
  1896. X#define VEL_ORG_Y        360
  1897. X#define VEL_LENGTH        ALT_LENGTH
  1898. X#define VEL_ORIENT        0
  1899. X#define VEL_SCALE        (170.0 / (double) VEL_LENGTH)
  1900. X#define VEL_INDEX_SIZE        30
  1901. X#define VEL_MIN_INTERVAL    10
  1902. X#define VEL_MIN_SIZE        8
  1903. X#define VEL_MAJ_INTERVAL    50
  1904. X#define VEL_MAJ_SIZE        15
  1905. X#define VEL_DIVISOR        10.0
  1906. X#define VEL_FORMAT        "%3.3g"
  1907. X
  1908. X#define HDG_ORG_X        (VIEW_WINDOW_WIDTH / 2 - (6*30+1) / 2)
  1909. X#define HDG_ORG_Y        400
  1910. X#define HDG_LENGTH        (6*30+1)
  1911. X#define HDG_ORIENT        0
  1912. X#define HDG_SCALE        (3000.0 / (double) VEL_LENGTH)
  1913. X#define HDG_INDEX_SIZE        10
  1914. X#define HDG_MIN_INTERVAL    500
  1915. X#define HDG_MIN_SIZE        5
  1916. X#define HDG_MAJ_INTERVAL    1000
  1917. X#define HDG_MAJ_SIZE        10
  1918. X#define HDG_DIVISOR        1000.0
  1919. X#define HDG_FORMAT        "%2.2g"
  1920. *-*-END-of-./fsim/pm.h-*-*
  1921. echo x - ./fsim/doViews.c
  1922. sed 's/^X//' >./fsim/doViews.c <<'*-*-END-of-./fsim/doViews.c-*-*'
  1923. X/*
  1924. X *    xflight : an aerial combat simulator for X
  1925. X *
  1926. X *    Written by Riley Rainey,  riley@mips.com
  1927. X *
  1928. X *    Permission to use, copy, modify and distribute (without charge) this
  1929. X *    software, documentation, images, etc. is granted, provided that this 
  1930. X *    comment and the author's name is retained.
  1931. X *
  1932. X */
  1933. X#include "pm.h"
  1934. X#include <math.h>
  1935. X
  1936. X#define lim    ((double) -1052500.0)
  1937. X
  1938. Xstatic VPoint    horiz[4] = {{-lim, -lim, (double) 0.0},
  1939. X            {-lim,  lim, (double) 0.0},
  1940. X            { lim,  lim, (double) 0.0},
  1941. X            { lim, -lim, (double) 0.0}};
  1942. X
  1943. X#define MAXPOLYGONS    8192
  1944. X
  1945. Xstatic VPolygon *poly[MAXPOLYGONS];
  1946. X
  1947. Xstatic craft *sortList;
  1948. X
  1949. Xvoid insertCraft();
  1950. X
  1951. Xvoid doViews() {
  1952. X
  1953. X    int    polyCount;
  1954. X    register unsigned long curPixel;
  1955. X    register craft    *c, *p;
  1956. X    register int    i, j, k;
  1957. X    register viewer *q;
  1958. X    VPoint         vp, fwd, up;
  1959. X    VPoint        horiz[4];
  1960. X    int        mono;
  1961. X
  1962. X/*
  1963. X *  Build a vector of polygons for all objects in the scene.
  1964. X *
  1965. X *  This vector should be ordered from "most distant" to "closest" so that
  1966. X *  the final display will end up correct.  Rather than generalizing this
  1967. X *  to death, we'll use a few heuristics to get very close to what we need:
  1968. X *
  1969. X *  (0) Build a single polygon to represent the ground.
  1970. X *  (1) Objects on the surface (stbl) are collected first.
  1971. X *  (2) Planes and projectiles (ptbl and mtbl) are first sorted in descending
  1972. X *      order by their distance from the observer and then polygons are
  1973. X *    collected.
  1974. X */
  1975. X
  1976. X
  1977. X    for ((i=0, c=ptbl); i<MAXPLAYERS; (++i, ++c)) {
  1978. X
  1979. X    if (c->type == CT_DRONE)
  1980. X        doDroneRadar (c);
  1981. X
  1982. X    if (c->type != CT_PLANE)
  1983. X        continue;
  1984. X
  1985. X/*
  1986. X *  Set up the eyespace transformation for this viewpoint
  1987. X */
  1988. X
  1989. X    VTransform (&c->cinfo->viewPoint, &(c->trihedral), &vp);
  1990. X    vp.x += c->Sg.x;
  1991. X    vp.y += c->Sg.y;
  1992. X    vp.z += c->Sg.z;
  1993. X
  1994. X    VTransform (&c->viewDirection, &(c->trihedral), &fwd);
  1995. X    fwd.x += vp.x;
  1996. X    fwd.y += vp.y;
  1997. X    fwd.z += vp.z;
  1998. X
  1999. X    VTransform (&c->viewUp, &(c->trihedral), &up);
  2000. X    up.x += vp.x;
  2001. X    up.y += vp.y;
  2002. X    up.z += vp.z;
  2003. X
  2004. X    VGetEyeSpace (c->vl->v, vp, fwd, up);
  2005. X
  2006. X    polyCount = 0;
  2007. X    sortList = (craft *) NULL;
  2008. X
  2009. X    horiz[0].x = c->Sg.x - lim;
  2010. X    horiz[0].y = c->Sg.y - lim;
  2011. X    horiz[0].z = 0.0;
  2012. X    horiz[1].x = c->Sg.x - lim;
  2013. X    horiz[1].y = c->Sg.y + lim;
  2014. X    horiz[1].z = 0.0;
  2015. X    horiz[2].x = c->Sg.x + lim;
  2016. X    horiz[2].y = c->Sg.y + lim;
  2017. X    horiz[2].z = 0.0;
  2018. X    horiz[3].x = c->Sg.x + lim;
  2019. X    horiz[3].y = c->Sg.y - lim;
  2020. X    horiz[3].z = 0.0;
  2021. X    
  2022. X    poly[0] = VCreatePolygon (4, &horiz[0], groundColor);
  2023. X    polyCount = 1;
  2024. X
  2025. X    for ((j=0, p=stbl); j<MAXSURFACE; (++j, ++p)) {
  2026. X        if (p->type != CT_FREE)
  2027. X/*            placeCraft (p, poly, &polyCount); */
  2028. X        insertCraft (c, p);
  2029. X    }
  2030. X
  2031. X    for ((j=0, p=ptbl); j<MAXPLAYERS; (++j, ++p)) {
  2032. X        if (p->type != CT_FREE && p != c) {
  2033. X        insertCraft (c, p);
  2034. X        }
  2035. X    }
  2036. X
  2037. X    for ((j=0, p=mtbl); j<MAXPROJECTILES; (++j, ++p)) {
  2038. X        if (p->type != CT_FREE)
  2039. X        insertCraft (c, p);
  2040. X    }
  2041. X
  2042. X    for (p=sortList; p != (craft *) NULL; p=(craft *)p->next)
  2043. X        placeCraft (p, poly, &polyCount);
  2044. X
  2045. X/*
  2046. X *  Clip all polygons
  2047. X */
  2048. X
  2049. X        for (j=0; j<polyCount; ++j) {
  2050. X            VTransformPolygon (poly[j], &(c->vl->v->eyeSpace));
  2051. X            poly[j] = VClipPolygon(poly[j], c->vl->v->clipPoly);
  2052. X    }
  2053. X
  2054. X/*
  2055. X *  Display this image for each viewer associated with this craft
  2056. X */
  2057. X
  2058. X    for (q=c->vl; q != NULL; q = q->next) {
  2059. X
  2060. X            mono = q->v->flags & VPMono;
  2061. X        curPixel = -1;
  2062. X            for (j=0; j<polyCount; ++j) {
  2063. X                if (poly[j]) {
  2064. X                    if (curPixel != (k=q->v->pixel[poly[j]->color->index])) {
  2065. X                        XSetForeground (q->dpy, q->gc, k);
  2066. X                        curPixel = k;
  2067. X                    }
  2068. X                    VFillPolygon (q->v, q->win, q->gc, poly[j]);
  2069. X                }
  2070. X
  2071. X           }
  2072. X
  2073. X/*  Draw Head-Up Display and instrument panel */
  2074. X
  2075. X        doHUD(c, q);
  2076. X        doRadar (c, q);
  2077. X        doTEWS (c, q);        /* doRadar must be called first */
  2078. X        doRPM(c, q);
  2079. X
  2080. X/*  Expose the completed drawing  */
  2081. X
  2082. X            VExposeBuffer (q->v, q->gc);
  2083. X
  2084. X/*
  2085. X * Erase the un-displayed planes.
  2086. X */
  2087. X
  2088. X        if (mono == 0) {
  2089. X                curPixel = *(q->v->pixel);
  2090. X                XSetForeground (q->dpy, q->gc, curPixel);
  2091. X                XFillRectangle (q->dpy, q->win, q->gc, 0, 0, q->width, q->height);
  2092. X        }
  2093. X
  2094. X    }
  2095. X
  2096. X/*
  2097. X *  Release polygons
  2098. X */
  2099. X
  2100. X        for (j=0; j<polyCount; ++j)
  2101. X            if (poly[j])
  2102. X            VDestroyPolygon (poly[j]);
  2103. X
  2104. X    }
  2105. X}
  2106. X
  2107. X/*
  2108. X *  insertCraft :  Insert a craft into sortList in descending order.
  2109. X */
  2110. X
  2111. Xvoid insertCraft (c, p)
  2112. Xcraft *c, *p; {
  2113. X
  2114. X    double dist, offset;
  2115. X    VPoint ds;
  2116. X    craft  *q, *prev;
  2117. X
  2118. X/*
  2119. X *  Here's a kludge for you:  to avoid polygon clipping, I'm going to 
  2120. X *  cheat and hack a way to get ground objects to display properly.
  2121. X *  if the Z coordinate of an object is zero (i.e. on ground objects),
  2122. X *  I'll add a huge offset to their distance values to force them to be
  2123. X *  plotted first -- and in roughly their correct drawing order.
  2124. X *
  2125. X */
  2126. X
  2127. X    offset = (p->Sg.z == 0.0) ? 1000.0 * NM : 0.0;
  2128. X
  2129. X    ds.x = p->Sg.x - c->Sg.x;
  2130. X    ds.y = p->Sg.y - c->Sg.y;
  2131. X    ds.z = p->Sg.z - c->Sg.z;
  2132. X    p->order = dist = mag (ds) + offset;
  2133. X
  2134. X    if (sortList != (craft *) NULL) {
  2135. X        for ((q=sortList, prev=(craft *) NULL); q != (craft *) NULL;) {
  2136. X        if (q->order < dist) {
  2137. X        p->next = (struct _craft *) q;
  2138. X        if (prev == (craft *) NULL)
  2139. X            sortList = p;
  2140. X        else
  2141. X            prev->next = (struct _craft *) p;
  2142. X        break;
  2143. X        }
  2144. X        prev = q;
  2145. X        q = (craft *) q->next;
  2146. X        }
  2147. X        if (q == (craft *) NULL) {
  2148. X        prev->next = (struct _craft *) p;
  2149. X        p->next = (struct _craft *) NULL;
  2150. X        }
  2151. X    }
  2152. X    else {
  2153. X        sortList = p;
  2154. X        p->next = (struct _craft *) NULL;
  2155. X    }
  2156. X}
  2157. X
  2158. Xint doHUD (c, u)
  2159. Xcraft  *c;
  2160. Xviewer *u; {
  2161. X
  2162. X    char    buffer[80];
  2163. X    int    i, x, x1, y;
  2164. X
  2165. X    if (c->viewDirection.x < 0.90)
  2166. X        return 0;
  2167. X    XSetFont (u->dpy, u->gc, u->font->fid);
  2168. X        XSetForeground (u->dpy, u->gc, u->v->pixel[HUDPixel]);
  2169. X    sprintf (buffer, "a=%.1f", RADtoDEG(c->alpha));
  2170. X    x = 730 * u->width / VIEW_WINDOW_WIDTH;
  2171. X    y = 130 * u->height / VIEW_WINDOW_HEIGHT;
  2172. X    XDrawString (u->dpy, u->win, u->gc, x, y, buffer, strlen(buffer));
  2173. X
  2174. X    x1 = 410 * u->width / VIEW_WINDOW_WIDTH;
  2175. X    sprintf (buffer, "%4.1f", c->G.z);
  2176. X    XDrawString (u->dpy, u->win, u->gc, x1, y, buffer, strlen(buffer));    
  2177. X
  2178. X    y = 390 * u->height / VIEW_WINDOW_HEIGHT;
  2179. X    sprintf (buffer, "%7d", (int)(-c->Cg.z * 60.0));
  2180. X    XDrawString (u->dpy, u->win, u->gc, x, y, buffer, strlen(buffer));
  2181. X
  2182. X    x = 410 * u->width / VIEW_WINDOW_WIDTH;
  2183. X    doCompassScale (u->dpy, u->win, u->gc, &(u->hdgScale), RADtoDEG(c->curHeading)*100.0,
  2184. X        u->fth, u->ftw);
  2185. X    doScale (u->dpy, u->win, u->gc, &(u->altScale), -c->Sg.z, u->fth, u->ftw);
  2186. X    doScale (u->dpy, u->win, u->gc, &(u->velScale), FPStoKTS(mag(c->Cg)),
  2187. X        u->fth, u->ftw);
  2188. X
  2189. X    sprintf (buffer, "%3d%% %s", (int)((double)c->throttle/327.68),
  2190. X        (c->flags & FL_AFTERBURNER) ? "AB" : "");
  2191. X    XDrawString (u->dpy, u->win, u->gc, x, y, buffer, strlen(buffer));
  2192. X
  2193. X    x = 380 * u->width / VIEW_WINDOW_WIDTH;
  2194. X    y = 420 * u->height / VIEW_WINDOW_HEIGHT;
  2195. X
  2196. X    doLadder (c, u);
  2197. X
  2198. X    for (i=0; i<3; ++i) {
  2199. X        XDrawString (u->dpy, u->win, u->gc, x, y, c->leftHUD[i],
  2200. X            strlen (c->leftHUD[i]));
  2201. X        y += u->fth;
  2202. X    }
  2203. X
  2204. X    return 0;
  2205. X
  2206. X}
  2207. X
  2208. Xstatic double L_half_width = 90.0;
  2209. Xstatic double L_end = 25.0;
  2210. Xstatic double L_height = 220.0;
  2211. Xstatic double L_major_tick_interval = 10.0;
  2212. Xstatic double L_major_tick_height = 90.0;
  2213. X
  2214. Xint    doLadder (c, u)
  2215. Xcraft *c;
  2216. Xviewer *u;{
  2217. X
  2218. X    double         x = c->curPitch, cx, s;
  2219. X    double        sinP, cosP, pixelsPerDegree;
  2220. X    XSegment    seg[24];
  2221. X    XRectangle    rect[1];
  2222. X    int        i, rung, windX, windY, w, tx, ty;
  2223. X    char        buf[16];
  2224. X    VPoint        tmp;
  2225. X
  2226. X    rect[0].x = u->xCenter - 125;
  2227. X    rect[0].y = u->yCenter - 110;
  2228. X    rect[0].width = 250;
  2229. X    rect[0].height = 220;
  2230. X
  2231. X    s = ((int)(RADtoDEG(x)) / 10 * 10) - 20;
  2232. X    rung = s;
  2233. X
  2234. X    pixelsPerDegree = L_major_tick_height / L_major_tick_interval;
  2235. X    cx = (RADtoDEG(x) - s) * pixelsPerDegree;
  2236. X    sinP = cos(c->curRoll);
  2237. X    cosP = sin(c->curRoll);
  2238. X    for (i=0; i<5; ++i, cx -= L_major_tick_height, rung +=10) {
  2239. X        seg[i*2].x1 = L_half_width * sinP + cx * cosP + u->xCenter;
  2240. X        seg[i*2].y1 = -L_half_width * cosP + cx * sinP + u->yCenter;
  2241. X        seg[i*2].x2 =  L_end * sinP + cx * cosP + u->xCenter;
  2242. X        seg[i*2].y2 = -L_end * cosP + cx * sinP + u->yCenter;
  2243. X        seg[i*2+1].x1 = -L_end * sinP + cx * cosP + u->xCenter;
  2244. X        seg[i*2+1].y1 = L_end * cosP + cx * sinP + u->yCenter;
  2245. X        seg[i*2+1].x2 =  -L_half_width * sinP + cx * cosP + u->xCenter;
  2246. X        seg[i*2+1].y2 = L_half_width * cosP + cx * sinP + u->yCenter;
  2247. X        sprintf (buf, "%d", rung);
  2248. X        if (seg[i*2].x1 >= rect[0].x && seg[i*2].x1 <
  2249. X            rect[0].x+rect[0].width &&
  2250. X            seg[i*2].y1 >= rect[0].y && seg[i*2].y1 <
  2251. X            rect[0].y+rect[0].height)
  2252. X            XDrawString (u->dpy, u->win, u->gc, 
  2253. X                seg[i*2].x1 + 2, seg[i*2].y1 + 5,
  2254. X                buf, strlen(buf));
  2255. X    }
  2256. X
  2257. X    i = i * 2;
  2258. X
  2259. X    XSetClipRectangles (u->dpy, u->gc, 0, 0, rect, 1, YXBanded);
  2260. X
  2261. X    windX = (int) (RADtoDEG(c->beta) * pixelsPerDegree) + u->xCenter;
  2262. X    windY = (int) (RADtoDEG(c->alpha) * pixelsPerDegree) + u->yCenter;
  2263. X
  2264. X    seg[i].x1 = windX - 18;
  2265. X    seg[i].y1 = windY;
  2266. X    seg[i].x2 = windX - 9;
  2267. X    seg[i++].y2 = windY;
  2268. X
  2269. X    seg[i].x1 = windX + 18;
  2270. X    seg[i].y1 = windY;
  2271. X    seg[i].x2 = windX + 9;
  2272. X    seg[i++].y2 = windY;
  2273. X
  2274. X    seg[i].x1 = windX;
  2275. X    seg[i].y1 = windY - 9;
  2276. X    seg[i].x2 = windX;
  2277. X    seg[i++].y2 = windY - 15;
  2278. X
  2279. X/*
  2280. X *  Gether weapon display info (and maybe draw a reticle).
  2281. X */
  2282. X
  2283. X    doWeaponDisplay (c, u);
  2284. X
  2285. X/*
  2286. X *  Draw a target designator around the current primary radar target.
  2287. X */
  2288. X
  2289. X    if (c->curRadarTarget >= 0) {
  2290. X
  2291. X        w = DESIGNATOR_SIZE * u->height / VIEW_WINDOW_HEIGHT * 0.5;
  2292. X
  2293. X        VTransform (&(ptbl[c->curRadarTarget].Sg),
  2294. X            &u->v->eyeSpace, &tmp);
  2295. X
  2296. X/* radar target is assumed to be ahead of us (tmp.z > 0.0) */
  2297. X        
  2298. X        tx = u->v->Middl.x + tmp.x * u->v->Scale.x / tmp.z;
  2299. X        ty = u->v->Middl.y - tmp.y * u->v->Scale.y / tmp.z;
  2300. X
  2301. X        seg[i].x1 = tx - w;
  2302. X        seg[i].y1 = ty - w;
  2303. X        seg[i].x2 = tx + w;
  2304. X        seg[i++].y2 = ty - w;
  2305. X
  2306. X        seg[i].x1 = tx + w;
  2307. X        seg[i].y1 = ty - w;
  2308. X        seg[i].x2 = tx + w;
  2309. X        seg[i++].y2 = ty + w;
  2310. X
  2311. X        seg[i].x1 = tx + w;
  2312. X        seg[i].y1 = ty + w;
  2313. X        seg[i].x2 = tx - w;
  2314. X        seg[i++].y2 = ty + w;
  2315. X
  2316. X        seg[i].x1 = tx - w;
  2317. X        seg[i].y1 = ty + w;
  2318. X        seg[i].x2 = tx - w;
  2319. X        seg[i++].y2 = ty - w;
  2320. X    }
  2321. X
  2322. X    XDrawSegments (u->dpy, u->win, u->gc, seg, i);
  2323. X    XDrawArc (u->dpy, u->win, u->gc, u->xCenter-2, u->yCenter-2, 4, 4, 0, 360*64);
  2324. X    XDrawArc (u->dpy, u->win, u->gc, windX-8, windY-8, 16, 16, 0, 360*64);
  2325. X
  2326. X    XSetClipMask (u->dpy, u->gc, None);
  2327. X
  2328. X    return 0;
  2329. X}
  2330. X
  2331. Xint    doRPM (c, u)
  2332. Xcraft *c;
  2333. Xviewer *u;{
  2334. X
  2335. X    int    x, y, x1, y1, len, i;
  2336. X    double  percent, p;
  2337. X    char    s[32], s1[32];
  2338. X
  2339. X    x = ENG_X * u->width / FS_WINDOW_WIDTH;
  2340. X    y = ENG_Y * u->width / FS_WINDOW_WIDTH;
  2341. X    len = (eng_x_hot - 6)* u->width / FS_WINDOW_WIDTH;
  2342. X
  2343. X    XSetForeground (u->dpy, u->gc, u->v->pixel[whitePixel]);
  2344. X    XSetBackground (u->dpy, u->gc, u->v->pixel[blackPixel]);
  2345. X    XCopyPlane (u->dpy, u->eng, u->win, u->gc, 0, 0, eng_width,eng_height,
  2346. X        x - eng_x_hot, y - eng_y_hot, 1);
  2347. X
  2348. X    percent = (double) c->throttle / 32768.0 * 100.0;
  2349. X    if (percent < 60.0) {
  2350. X        p = (60.0 - percent) / 120.0 * pi;
  2351. X        x1 = x + len * cos(p);
  2352. X        y1 = y - len * sin(p);
  2353. X    }
  2354. X    else {
  2355. X        p = (percent - 60.0) / 40.0 * pi;
  2356. X        x1 = x + len * cos(p);
  2357. X        y1 = y + len * sin(p); 
  2358. X    }
  2359. X
  2360. X    XDrawLine (u->dpy, u->win, u->gc, x, y, x1, y1);
  2361. X
  2362. X/*
  2363. X *  Print Fuel and Fuel consumption rate
  2364. X */
  2365. X
  2366. X    sprintf (s, "%7s lbs Total", ItoA ((int) c->fuel, s1));
  2367. X    XDrawImageString (u->dpy, u->win, u->gc, x-30, y+68, s, strlen(s));
  2368. X    sprintf (s, "%7s lbs/hour", ItoA ((int) (fuelUsed(c)*3600.0/deltaT), s1));
  2369. X    XDrawImageString (u->dpy, u->win, u->gc, x-30, y+68+u->fth, s, strlen(s));
  2370. X
  2371. X/*
  2372. X *  Display Flap Setting
  2373. X */
  2374. X
  2375. X    if (c->flapSetting > DEGtoRAD(29.0))
  2376. X        i=3;
  2377. X    else if (c->flapSetting > DEGtoRAD(19.0))
  2378. X        i=2;
  2379. X    else if (c->flapSetting > DEGtoRAD(9.0))
  2380. X        i=1;
  2381. X    else
  2382. X        i=0;
  2383. X
  2384. X    x = FLAP_X * u->width / FS_WINDOW_WIDTH;
  2385. X    y = FLAP_Y * u->width / FS_WINDOW_WIDTH;
  2386. X
  2387. X    XCopyPlane (u->dpy, u->flap[i], u->win, u->gc, 0, 0, flaps0_width,
  2388. X        flaps0_height, x, y, 1);
  2389. X    sprintf (s, "Flaps: %d", (int) RADtoDEG(c->curFlap));
  2390. X    XDrawImageString (u->dpy, u->win, u->gc, x+flaps0_x_hot, y+flaps0_y_hot,
  2391. X        s, strlen(s));
  2392. X
  2393. X    return 0;
  2394. X}
  2395. *-*-END-of-./fsim/doViews.c-*-*
  2396. -- 
  2397. Riley Rainey            Internet: riley@mips.com
  2398. MIPS Computer Systems        Phone:    +1 214 770-7979
  2399. Dallas, Texas
  2400.  
  2401. dan
  2402. ----------------------------------------------------
  2403. O'Reilly && Associates   argv@sun.com / argv@ora.com
  2404. Opinions expressed reflect those of the author only.
  2405.